From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 0083C3946C36 for ; Wed, 19 May 2021 22:52:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0083C3946C36 Received: by mail-pj1-x102a.google.com with SMTP id ep16-20020a17090ae650b029015d00f578a8so4218709pjb.2 for ; Wed, 19 May 2021 15:52:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=K/gtSQyGUSDU2Jx3SxY9nAC3F0K9RnJVQwhiYzkSGHo=; b=lQd5WGOpIddDpiyJbgqAd2x0izIbVcoCK2wNoL2E2hh8QxAt0yT29oeMNfg63EAPAm 1kjtrTM8ihZQUrkOwT/pvRAEzmrugmvQ/3Ik37hm7TGBLUoMCczfXdOESX2GsPB9RGkx aKbAd8uTEYrofgGS15ROp5gNAxjXbzqwQPN9ymVYRvW2MLJeNecq12UGkmOJ2W4oEyfC nV10SctyBX0Pa0OHmu0VPztGpt/XZ0XM71f6OWCSQ3yY5NXz2mN+m7EddDTrtqlIxXMx 6qjdxhyMrtbKfP4SpDggPuOfzE7owKb7zaY4ba9piSoousrbxc7PbkuDiebaEdVCCCAk TOOg== X-Gm-Message-State: AOAM531By36xupemtWTQf8eiG5hOsrbH5Vdg1P7c+fmOQFP6TnyO4M5l 3XQilVwsq1hFee94KVoJV/+iqIYXiGJPFw== X-Google-Smtp-Source: ABdhPJwwHW0r8aMTiKvsh1z2gjgvHDbBcxnmnURC+BE3zkCPCR2+LFtab8vdgFm6O8pyoHn65LB4gQ== X-Received: by 2002:a17:902:a40e:b029:e9:7253:8198 with SMTP id p14-20020a170902a40eb02900e972538198mr2160441plq.82.1621464720134; Wed, 19 May 2021 15:52:00 -0700 (PDT) Received: from localhost (60-241-27-127.tpgi.com.au. [60.241.27.127]) by smtp.gmail.com with ESMTPSA id gg10sm364500pjb.49.2021.05.19.15.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 15:51:59 -0700 (PDT) Date: Thu, 20 May 2021 08:51:53 +1000 From: Nicholas Piggin Subject: Re: Linux powerpc new system call instruction and ABI To: "Dmitry V. Levin" , Michael Ellerman Cc: Joakim Tjernlund , libc-alpha@sourceware.org, libc-dev@lists.llvm.org, linux-api@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Matheus Castanho , musl@lists.openwall.com References: <20210519132656.GA17204@altlinux.org> In-Reply-To: <20210519132656.GA17204@altlinux.org> MIME-Version: 1.0 Message-Id: <1621464056.o9t21cquw8.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 May 2021 22:52:02 -0000 Excerpts from Dmitry V. Levin's message of May 19, 2021 11:26 pm: > On Wed, May 19, 2021 at 08:59:05PM +1000, Nicholas Piggin wrote: >> Excerpts from Dmitry V. Levin's message of May 19, 2021 8:24 pm: >> > On Wed, May 19, 2021 at 12:50:24PM +1000, Nicholas Piggin wrote: >> > [...] >> >> With this patch, I think the ptrace ABI should mostly be fixed. I thi= nk=20 >> >> a problem remains with applications that look at system call return=20 >> >> registers directly and have powerpc specific error cases. Those proba= bly >> >> will just need to be updated unfortunately. Michael thought it might = be >> >> possible to return an indication via ptrace somehow that the syscall = is >> >> using a new ABI, so such apps can be updated to test for it. I don't=20 >> >> know how that would be done. >> >=20 >> > Is there any sane way for these applications to handle the scv case? >> > How can they tell that the scv semantics is being used for the given >> > syscall invocation? Can this information be obtained e.g. from struct >> > pt_regs? >>=20 >> Not that I know of. Michael suggested there might be a way to add=20 >> something. ptrace_syscall_info has some pad bytes, could >> we use one for flags bits and set a bit for "new system call ABI"? >=20 > PTRACE_GET_SYSCALL_INFO is an architecture-agnostic API, it hides all > architecture-specific details behind struct ptrace_syscall_info which has > the same meaning on all architectures. ptrace_syscall_info.exit contains > both rval and is_error fields to support every architecture regardless of > its syscall ABI. >=20 > ptrace_syscall_info.exit is extensible, but every architecture would have > to define a method of telling whether the system call follows the "new > system call ABI" conventions to export this bit of information. It's already architecture speicfic if you look at registers of syscall=20 exit state so I don't see a problem with a flag that ppc can use for ABI. >=20 > This essentially means implementing something like > static inline long syscall_get_error_abi(struct task_struct *task, struct= pt_regs *regs) > for every architecture, and using it along with syscall_get_error > in ptrace_get_syscall_info_exit to initialize the new field in > ptrace_syscall_info.exit structure. Yes this could work. Other architectures can just use a generic implementation if they don't define their own so that's easy. And in userspace they can continue to ignore the flag. >=20 >> As a more hacky thing you could make a syscall with -1 and see how >> the error looks, and then assume all syscalls will be the same. >=20 > This would be very unreliable because sc and scv are allowed to interming= le, > so every syscall invocation can follow any of these two error handling > conventions. >=20 >> Or... is it possible at syscall entry to peek the address of >> the instruction which caused the call and see if that was a >> scv instruction? That would be about as reliable as possible >> without having that new flag bit. >=20 > No other architecture requires peeking into tracee memory just to find ou= t > the syscall ABI. This would make powerpc the most ugly architecture for > ptracing. >=20 > I wonder why can't this information be just exported to the tracer via > struct pt_regs? It might be able to, I don't see why that would be superior though. Where could you put it... I guess it could go in the trap field in a=20 high bit. But could that break things that just test for syscall=20 trap number (and don't care about register ABI)? I'm not sure. Thanks, Nick