From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7598AC43603 for ; Wed, 18 Dec 2019 14:13:46 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 285622146E for ; Wed, 18 Dec 2019 14:13:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=axtens.net header.i=@axtens.net header.b="oWvc6zF1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 285622146E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47dH6w1pQxzDqkK for ; Thu, 19 Dec 2019 01:13:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::642; helo=mail-pl1-x642.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="oWvc6zF1"; dkim-atps=neutral Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47dH4Y45wgzDqYJ for ; Thu, 19 Dec 2019 01:11:41 +1100 (AEDT) Received: by mail-pl1-x642.google.com with SMTP id p27so1021621pli.10 for ; Wed, 18 Dec 2019 06:11:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=5OhHylg1TPaS47GWjrsnP2qwXLa5vXD4hGq2zAGcEfs=; b=oWvc6zF1ihRDNoGErmk2HnXeDznlrEO1N1u9jrY/Z/Uy46t0B1ppRJYfWJv8QXE7db xo6XAY7i+TLMKj3BeG0h4t7lr5ER9a15uQe5vSqlT8SDammaArDjUOJFP2GmMZ9gqnzF z+vOvB/gZxxe8Vtknz6bbmlOklifvUV3vBmuI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=5OhHylg1TPaS47GWjrsnP2qwXLa5vXD4hGq2zAGcEfs=; b=m0HBQHwY+4BffBpYxe+ORqFVNTVAUfy3y0PoTYNI2ji3wiX+6ccol2Cmx/gtZ4G7eI qQxwLlGu7ehujgkXPtZ9uCoSGUUFCK9eFIECfIOkmn82heyd7roXKKr9mM/6qaE6S0pr vgxqeesEN6oo6SUnlK7/xGnfw1N88WUu8X9jhzSMS22wMsxfbf9bTsHo5rMOJ5XLK5M2 PQsiRl5R7NI2DZkniojW4LqFT7V24V6TZ7JeSmjGYGUT7pQ7wkbGuDZGdq7/a7CZ2+Jz geJCc69u0TFPCTDeEMS01j27KVfJGWHOCdwKUMZoyQoicnx9HPBUeZl/RCkB2cb8K9Ja Mzig== X-Gm-Message-State: APjAAAVJ8itCwkC/W9IPV2rY19lxTFQpUnmSB089xBeolwyx5A7lTKkk VmltBmAkgWnQzVJMTsNywzWvQw== X-Google-Smtp-Source: APXvYqwukeiV0v6+KS+yMuVFNifu19LOoW/2ya5bfEU+3And/oSH6XBzRlEKXUHlILALMTatf4LyKw== X-Received: by 2002:a17:90a:8545:: with SMTP id a5mr2994553pjw.3.1576678297757; Wed, 18 Dec 2019 06:11:37 -0800 (PST) Received: from localhost (2001-44b8-1113-6700-a084-b324-40b3-453d.static.ipv6.internode.on.net. [2001:44b8:1113:6700:a084:b324:40b3:453d]) by smtp.gmail.com with ESMTPSA id r3sm3538735pfg.145.2019.12.18.06.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2019 06:11:36 -0800 (PST) From: Daniel Axtens To: Jordan Niethe , linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH 18/18] powerpc/fault: Use analyse_instr() to check for store with updates to sp In-Reply-To: <20191126052141.28009-19-jniethe5@gmail.com> References: <20191126052141.28009-1-jniethe5@gmail.com> <20191126052141.28009-19-jniethe5@gmail.com> Date: Thu, 19 Dec 2019 01:11:33 +1100 Message-ID: <87immdu3je.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au, Jordan Niethe Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Jordan Niethe writes: > A user-mode access to an address a long way below the stack pointer is > only valid if the instruction is one that would update the stack pointer > to the address accessed. This is checked by directly looking at the > instructions op-code. As a result is does not take into account prefixed > instructions. Instead of looking at the instruction our self, use > analyse_instr() determine if this a store instruction that will update > the stack pointer. > > Something to note is that there currently are not any store with update > prefixed instructions. Actually there is no plan for prefixed > update-form loads and stores. So this patch is probably not needed but > it might be preferable to use analyse_instr() rather than open coding > the test anyway. Yes please. I was looking through this code recently and was horrified. This improves things a lot and I think is justification enough as-is. Regards, Daniel > > Signed-off-by: Jordan Niethe > --- > arch/powerpc/mm/fault.c | 39 +++++++++++---------------------------- > 1 file changed, 11 insertions(+), 28 deletions(-) > > diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c > index b5047f9b5dec..cb78b3ca1800 100644 > --- a/arch/powerpc/mm/fault.c > +++ b/arch/powerpc/mm/fault.c > @@ -41,37 +41,17 @@ > #include > #include > #include > +#include > > /* > * Check whether the instruction inst is a store using > * an update addressing form which will update r1. > */ > -static bool store_updates_sp(unsigned int inst) > +static bool store_updates_sp(struct instruction_op *op) > { > - /* check for 1 in the rA field */ > - if (((inst >> 16) & 0x1f) != 1) > - return false; > - /* check major opcode */ > - switch (inst >> 26) { > - case OP_STWU: > - case OP_STBU: > - case OP_STHU: > - case OP_STFSU: > - case OP_STFDU: > - return true; > - case OP_STD: /* std or stdu */ > - return (inst & 3) == 1; > - case OP_31: > - /* check minor opcode */ > - switch ((inst >> 1) & 0x3ff) { > - case OP_31_XOP_STDUX: > - case OP_31_XOP_STWUX: > - case OP_31_XOP_STBUX: > - case OP_31_XOP_STHUX: > - case OP_31_XOP_STFSUX: > - case OP_31_XOP_STFDUX: > + if (GETTYPE(op->type) == STORE) { > + if ((op->type & UPDATE) && (op->update_reg == 1)) > return true; > - } > } > return false; > } > @@ -278,14 +258,17 @@ static bool bad_stack_expansion(struct pt_regs *regs, unsigned long address, > > if ((flags & FAULT_FLAG_WRITE) && (flags & FAULT_FLAG_USER) && > access_ok(nip, sizeof(*nip))) { > - unsigned int inst; > + unsigned int inst, sufx; > + struct instruction_op op; > int res; > > pagefault_disable(); > - res = __get_user_inatomic(inst, nip); > + res = __get_user_instr_inatomic(inst, sufx, nip); > pagefault_enable(); > - if (!res) > - return !store_updates_sp(inst); > + if (!res) { > + analyse_instr(&op, uregs, inst, sufx); > + return !store_updates_sp(&op); > + } > *must_retry = true; > } > return true; > -- > 2.20.1