From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id A713B3857033 for ; Thu, 20 May 2021 02:40:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A713B3857033 Received: by mail-pl1-x62a.google.com with SMTP id z4so5965616plg.8 for ; Wed, 19 May 2021 19:40:43 -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=j6sMI+bZA9YMbk0fCYjyAAWKqPr1erMiXEBhyqYazhg=; b=ocGv1axTPs81y4V/jXMfToCW3eiTO0pQp/Oup4nJS+CCRKFfxBZ5ms4qTS84v7Qq8+ HxBd6TK6lv9RaNgeqCSBA9OU7CPye2RChzo35B2jhI/1vx9D9al1jWtODKOu6FDtB1cL cpKgFEEWdMIbi0TKMtElLwKyed+ZhVBMzVf+I/pgHyC7nr/Ihfydc6bz3ZUwZjnXa5es bxa8gMD7GAuIaNwqbAzqI2Xyb98oCZmk9hDlCcgKgDkuHMQTbQeDg7TuGJENDcBVs+xJ f+yftkgyUCgvI6HyutcY5MuV2kFsv8slN0VzbGAdohceP2ye2+wFRZrTJ2OOy0ProM6P 748w== X-Gm-Message-State: AOAM530HXRPWZ633o4T8ZJK/2PWBhgiKOGh7pwPI/3Txsgaa707mqUtZ NB9zrt4GO4HOpiW3bap2QGs= X-Google-Smtp-Source: ABdhPJxyeeNTthbt4jQGW2C22vOGa/e/gQB/AVNS+yPXRn6R5CDD986w6024+wQ1CIyHmrgxIv4bWA== X-Received: by 2002:a17:902:7795:b029:f2:63cb:ab16 with SMTP id o21-20020a1709027795b02900f263cbab16mr3104479pll.7.1621478442283; Wed, 19 May 2021 19:40:42 -0700 (PDT) Received: from localhost (60-241-27-127.tpgi.com.au. [60.241.27.127]) by smtp.gmail.com with ESMTPSA id c19sm22268pfo.150.2021.05.19.19.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 19:40:41 -0700 (PDT) Date: Thu, 20 May 2021 12:40:36 +1000 From: Nicholas Piggin Subject: Re: Linux powerpc new system call instruction and ABI To: "Dmitry V. Levin" Cc: Joakim Tjernlund , libc-alpha@sourceware.org, libc-dev@lists.llvm.org, linux-api@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Matheus Castanho , musl@lists.openwall.com References: <20210519132656.GA17204@altlinux.org> <1621464056.o9t21cquw8.astroid@bobo.none> <20210519232726.GA24134@altlinux.org> In-Reply-To: <20210519232726.GA24134@altlinux.org> MIME-Version: 1.0 Message-Id: <1621478238.xha1ow4ujh.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: Thu, 20 May 2021 02:40:45 -0000 Excerpts from Dmitry V. Levin's message of May 20, 2021 9:27 am: > On Thu, May 20, 2021 at 08:51:53AM +1000, Nicholas Piggin wrote: >> 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 = think=20 >> >> >> a problem remains with applications that look at system call retur= n=20 >> >> >> registers directly and have powerpc specific error cases. Those pr= obably >> >> >> will just need to be updated unfortunately. Michael thought it mig= ht be >> >> >> possible to return an indication via ptrace somehow that the sysca= ll 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 give= n >> >> > syscall invocation? Can this information be obtained e.g. from str= uct >> >> > 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 conta= ins >> > 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 h= ave >> > to define a method of telling whether the system call follows the "new >> > system call ABI" conventions to export this bit of information. >>=20 >> 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 > To be honest, I don't see anything architecture-specific in > PTRACE_GET_SYSCALL_INFO API. Yes, it's implementation uses various > functions defined in asm/syscall.h, but this doesn't make the interface > architecture-specific. No. But a field or flag it exports could be architecture dependent. It doesn't detract independence from the rest of the ABI. That said... > PTRACE_GET_SYSCALL_INFO saves its users from necessity to be aware of > tracee registers. That's why the only place where strace has to deal > with tracee registers nowadays is syscall tampering. The most reliable > solution is to introduce PTRACE_SET_SYSCALL_INFO, this would make the > whole syscall abi issue irrelevant for ptracers, maybe the time has come > to implement it. >=20 > Unfortunately, extending ptrace API takes time, and it's not going to be > backported to older kernels anyway, but scv-enabled kernels are already > in the wild, so we need a quick powerpc-specific fix that would be > backported to all maintained scv-enabled kernels. >=20 > [...] >> > I wonder why can't this information be just exported to the tracer via >> > struct pt_regs? >>=20 >> It might be able to, I don't see why that would be superior though. >>=20 >> 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. >=20 > Looks like struct pt_regs.trap already contains the information that coul= d > be used to tell 'sc' from 'scv': if (pt_regs.trap & ~0xf) =3D=3D 0x3000, = then > it's scv. Is my reading of arch/powerpc/include/asm/ptrace.h correct? Hmm, I think it is. Certainly in the kernel regs struct it is, I had in=20 my mind that we put it to 0xc00 when populating the user struct for compatibility, but it seems not. So I guess this would work. Thanks, Nick