Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1614411imu; Wed, 12 Dec 2018 00:57:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/WqNvL9exoDUATcdUHgmKXLtAkZjOZMqD3zwojObTeECY+xl1MV0V3UZaIUYijoaMccwGNC X-Received: by 2002:a17:902:8c98:: with SMTP id t24mr19063041plo.130.1544605059593; Wed, 12 Dec 2018 00:57:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544605059; cv=none; d=google.com; s=arc-20160816; b=uTqbiXrZJJJP1xiJXNCF9i5w0/4y4mWc4TReY33Vvk+ieagzaVPfo1975k27Q2izt6 cH4sgpMolPDzgYETJC6veOrbqsu2/Yu0vSqMx5A9a9DB7LtlAR9P5G4nSMxuy1O53WGU CDzHG9xwbPbPEGu/HroGJTnnAzhztj0JufhQgy6dno8a5IdYmflUO4wCupVaBCNvClMp 2z0fXIVK8ZNYn6dg54u8cXYrH8zKrgQfSrt/6MRfn/v6hjvJMdrpqXiCfBL59f/IP5QX KRHqgZ6siyAqkL3ErFoKUPs1qSEuR8oFsNoc0e+5a4IHEY0ZmjvDxv7RsHbgHU3trmI2 AkoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=F4bn/uUN7DdXvzUbqPnc2O4rKIa8CjCkQ/3QFz5mVjE=; b=A79Xw6E2BlTnw7ejkSzDet16ENHvpsNYOysjiWwHSUA6qjB0AcCj+lv4u/M8n8o7AP Okwisoer4nSjbODOnedE5iKxFkb2GO+4GXvpX/Hh92t0s+L+/y7kBcJbH4u+DfmkZmNB mlxzyz9Mux7hzFG7aZt2L2ulY/Cqt0n16DnfgUQn8pGQqh8gTsIZzUrW6VOc2inxp7OS ePfnmGXCgkItkEslSKUh32khpGYKkO6i/vyxRAqqlDW9TZ+HhlqbRmhQRY/utdCdOx2X fhHF7Ngd4jztt9mmq7PIYV5q/QL8fPsV+wATQi1aFxPOdE0gBFfcHsPAxSDiNJBjADJ9 xQug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2si16681765pfc.82.2018.12.12.00.57.24; Wed, 12 Dec 2018 00:57:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbeLLIzS (ORCPT + 99 others); Wed, 12 Dec 2018 03:55:18 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:33528 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbeLLIzS (ORCPT ); Wed, 12 Dec 2018 03:55:18 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 3C1E672CA56; Wed, 12 Dec 2018 11:55:16 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 327137CFE41; Wed, 12 Dec 2018 11:55:16 +0300 (MSK) Date: Wed, 12 Dec 2018 11:55:16 +0300 From: "Dmitry V. Levin" To: Geert Uytterhoeven Cc: Oleg Nesterov , Andy Lutomirski , lineprinter@altlinux.org, Eugene Syromiatnikov , linux-m68k , Linux Kernel Mailing List Subject: Re: [PATCH v5 13/25] m68k: add asm/syscall.h Message-ID: <20181212085516.GA13288@altlinux.org> References: <20181210042352.GA6092@altlinux.org> <20181210043010.GM6131@altlinux.org> <20181210124059.GA11942@altlinux.org> <20181210133025.GG11942@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2fHTh5uZTiUOsy+g" Content-Disposition: inline In-Reply-To: <20181210133025.GG11942@altlinux.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote: > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote: > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin wrot= e: > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote: > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin = wrote: > > > > > syscall_get_* functions are required to be implemented on all > > > > > architectures in order to extend the generic ptrace API with > > > > > PTRACE_GET_SYSCALL_INFO request. > > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_= get_* > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr, > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_valu= e, > > > > > and syscall_get_arch. > > > > > > > > > > Cc: Geert Uytterhoeven > > > > > Cc: Oleg Nesterov > > > > > Cc: Andy Lutomirski > > > > > Cc: Elvira Khabirova > > > > > Cc: Eugene Syromyatnikov > > > > > Cc: linux-m68k@lists.linux-m68k.org > > > > > Signed-off-by: Dmitry V. Levin > > > > > --- > > > > > > > > > > Notes: > > > > > v5: added syscall_get_nr, syscall_get_arguments, syscall_get_= error, > > > > > and syscall_get_return_value > > > > > v1: added syscall_get_arch > > > > > > > > > --- /dev/null > > > > > +++ b/arch/m68k/include/asm/syscall.h > > > > > @@ -0,0 +1,39 @@ > > > > > > > > > +static inline void > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *= regs, > > > > > + unsigned int i, unsigned int n, unsigned lo= ng *args) > > > > > +{ > > > > > + BUG_ON(i + n > 6); > > > > > > > > Does this have to crash the kernel? > > > > > > This is what most of other architectures do, but we could choose > > > a softer approach, e.g. use WARN_ON_ONCE instead. > > > > > > > Perhaps you can return an error code instead? > > > > > > That would be problematic given the signature of this function > > > and the nature of the potential bug which would most likely be a usag= e error. > >=20 > > Of course to handle that, the function's signature need to be changed. > > Changing it has the advantage that the error handling can be done at the > > caller, in common code, instead of duplicating it for all > > architectures, possibly > > leading to different semantics. >=20 > Given that *all* current users of syscall_get_arguments specify i =3D=3D 0 > (and there is an architecture that has BUG_ON(i)),=20 > it should be really a usage error to get into situation where i + n > 6, > I wish a BUILD_BUG_ON could be used here instead. >=20 > I don't think it worths pushing the change of API just to convert > a "cannot happen" assertion into an error that would have to be dealt with > on the caller side. I suggest the following BUG_ON replacement for syscall_get_arguments: #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, unsigned int i, unsigned int n, unsigned long *args) { /* * Ideally there should have been * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS); * instead of these checks. */ if (unlikely(i > SYSCALL_MAX_ARGS)) { WARN_ONCE(1, "i > SYSCALL_MAX_ARGS"); return; } if (unlikely(n > SYSCALL_MAX_ARGS - i)) { WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS"); n =3D SYSCALL_MAX_ARGS - i; } BUILD_BUG_ON(sizeof(regs->d1) !=3D sizeof(args[0])); memcpy(args, ®s->d1 + i, n * sizeof(args[0])); } --=20 ldv --2fHTh5uZTiUOsy+g Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJcEMzzAAoJEAVFT+BVnCUIJTsQAOmj7OloZvGD8dgggADIyI0s z5azwyQpfO3yX7sYLZxpg7SrZEmwSiv9wer6S5nQDQ6QXHisZYp7L/aI+h4tuCoe HlOUxX8etVSCqZgWZMgooylO8D9roSbHjfsSC7hTReunMeY+xv9nLYTvXnyP4TdL URVu4vLNatpFsXzWiK5qCH9QodBIklZrt0M1OjCeVrn+kV5Ui9gK0lbfcfGK0H0C 445bHjFgmtZVxPgpy6foekRYiLvijoVNMTxOHakEhSOFO3RnStcGHRj8sXlzoiBo pu9NSx62F6iSLPR/AL8adJKpcNOTp52GT4QNYnXLQezMgWSbi495+54RKjFfui6/ eC2MVBZpPMktYA8XsgMNYdDOW+IbbNvxvfMZ2ZhF3G+9jiI8BaigD4zhI6qU6Ddf Urx/hRcR/1tCaTDBnALfokI2yioPen6pR4bztzdns7jK+LIGbTzPwO/RZXGd+Z2x k/TABg0u619M+TQcjkYLeuJ/8Xirpoo3YnIECs9ojuMUkCpZbBRlrqDsDerkRvjm 3TlmRWM7PZou2EvMBnB0+CTID8s/dxBXMRAZuQu5yWoqwWrRTKzx8AMWJv9ymQV9 ocDp7nFiIWy4HpvK1s+dkT3+4FKPy4nq1p9XAVd/a1BB55V3TQILwj2BGLr/FWfp 5Gl+JhJCCcikFhQMuOKt =mDWX -----END PGP SIGNATURE----- --2fHTh5uZTiUOsy+g--