Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1043512pxk; Fri, 25 Sep 2020 04:56:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA1wB6moJyubhzHx2mSESZXKl890ELYBq6h6wZEAZMv59jy66xbc1hgZa54VWf/Wbs3Z01 X-Received: by 2002:a17:906:2b83:: with SMTP id m3mr2299395ejg.456.1601034962696; Fri, 25 Sep 2020 04:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601034962; cv=none; d=google.com; s=arc-20160816; b=dNdKwWfGZy/FJI+qRHTcNl2D47V93+XY+cXx4HdxrGoyYlXbTQDGc6CU0aWK8mQTJN Xy3zp3HDZ126D64qscBVIY8I8LTZeAOZdnsNtzBfhQ2G2xlRYvbvDkx7J0X6/dUPFr3O qjUvwBvMKg9aSLDOaTkPX7gGD2YRqiuIyvjMn+HACkUvawZv29iooEQZJlkrvU+fHIYT /hzG6XMZgA2O/0ggyEk6Wj7WUn8QpJyTnW5z0GXHIfjY+CTETD8r7+96i740Enm5bytC zysuZeHXaQy8qrPlLzuEAZ//0p/zcaYBwP3MOdLTintp/0dejcRKyP62HmX4DYE3wUyV zWyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=A1oOkyfsqFH1LfQrqPkW7aNFfIeXKev/R5cazxL0aFM=; b=OqAnTrMo9KIpXhV7wt9JJyxmT4yR975pp2OaZx9zRpvup7swJ3jcdYyGpUGTKz5S84 QT8XSe10yBpGP41nZm8dsYs+ACWamcyarrfBXbJBNG87umVzgOocP2N4fNn7emZ9xDZm eqafHmt4GoR4AJFDDUp7sW5DrYbM+wXrW90P5prpuVrSn0bk5nULUUDUShPhKpiFoGg+ btLpVvDXVKKbL91shVF2HSwZmHBy094hABLtQeFUr3Jkr5PIXaXZ9/wyvMJcna+qyd6D KCHUxhvoYfYF78sIWHymABXWPhUpcuQFIo5enQ4/DuyynfIZRjwt5qTXTtyU4uYjBMZ1 tuMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VNgZuBxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x23si1695310ejj.642.2020.09.25.04.55.39; Fri, 25 Sep 2020 04:56:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VNgZuBxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728328AbgIYLxI (ORCPT + 99 others); Fri, 25 Sep 2020 07:53:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728118AbgIYLxH (ORCPT ); Fri, 25 Sep 2020 07:53:07 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEEE1C0613CE for ; Fri, 25 Sep 2020 04:53:07 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id x16so1566265pgj.3 for ; Fri, 25 Sep 2020 04:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A1oOkyfsqFH1LfQrqPkW7aNFfIeXKev/R5cazxL0aFM=; b=VNgZuBxUpAgJ8TImvaNn2mHkfg9QdQXl830VbRYRx2TXZC7HlzA0A11WFHU3nH9AYz Cc3KAsNx7MblsfZCJ+9RFgyH70bkLziaw2lR6NWTlmwozfDYdjaeNUEUuZyIE03fWCqL F9JjA5ryhGFZPYkXihGXzaKj4V1T2+Y1T8x2uZrBAm/SkvIVkUDUiRWOkOBSfCT8f0hU H/+Kr/rWddToxWq705+hpL4PrXmXFwpIcx+bZJ4xlYWWAv6eV7UR8xg7h/OV3I9GRNQa zVnpLvCcENqK5uXej0r63VuhHMzJH5wI6CKS+QceAoxK+raeyg9olUJUF1HPGKpkwH77 7x4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A1oOkyfsqFH1LfQrqPkW7aNFfIeXKev/R5cazxL0aFM=; b=rrUaL5sCtLouPU7Bs6ft/xM6bs6/cxbt68cbjJEFl4dV/TCrln9vzY86iCQcAYxuaK ky79NkoYgIpvbA5+k68DCjxSYUc6tqKR23s7RtjAePFRx8iHmDYlGfdAH0G3SiSxk4KG 8J/xTZUkAlYj+ivLfv4qyBKTamZGLKDFFAUK8tixUxmdJTkijfo6dDlgDGLwlJG20NCI zxAiRbUWWVfScy1fVdowYInNwNf3aLYIe4EfUl+KNn20Q/HhYDBNYgCB8sitJqMV1l8e 7hKFa5mxcDHZasbxx2xqfvBkEu5Y0ANxlOnlsefK/BYgEe4VlMexDMlzrKVV8yawqxhq 1VLQ== X-Gm-Message-State: AOAM533bcaPf6vaOIOV4jEHhhtlDHzBuzenW6hVAuVZfgqVF8gYP6s3h C8RAe6JfBJrU2NhGGtmTJJDQqX8Ya4Abgv3X3s0jCg== X-Received: by 2002:a17:902:b117:b029:d1:e5e7:bdf5 with SMTP id q23-20020a170902b117b02900d1e5e7bdf5mr3803333plr.85.1601034787254; Fri, 25 Sep 2020 04:53:07 -0700 (PDT) MIME-Version: 1.0 References: <17ec8af55dc0a4d3ade679feb0858f0df4c80d27.1600987622.git.andreyknvl@google.com> <20200925104933.GD4846@gaia> <20200925114703.GI4846@gaia> In-Reply-To: <20200925114703.GI4846@gaia> From: Andrey Konovalov Date: Fri, 25 Sep 2020 13:52:56 +0200 Message-ID: Subject: Re: [PATCH v3 26/39] arm64: mte: Add in-kernel tag fault handler To: Catalin Marinas Cc: Dmitry Vyukov , Vincenzo Frascino , kasan-dev , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 25, 2020 at 1:47 PM Catalin Marinas wrote: > > On Fri, Sep 25, 2020 at 01:26:02PM +0200, Andrey Konovalov wrote: > > On Fri, Sep 25, 2020 at 12:49 PM Catalin Marinas > > wrote: > > > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > > > > index a3bd189602df..d110f382dacf 100644 > > > > --- a/arch/arm64/mm/fault.c > > > > +++ b/arch/arm64/mm/fault.c > > > > @@ -33,6 +33,7 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > #include > > > > #include > > > > #include > > > > @@ -294,6 +295,11 @@ static void die_kernel_fault(const char *msg, unsigned long addr, > > > > do_exit(SIGKILL); > > > > } > > > > > > > > +static void report_tag_fault(unsigned long addr, unsigned int esr, > > > > + struct pt_regs *regs) > > > > +{ > > > > +} > > > > > > Do we need to introduce report_tag_fault() in this patch? It's fine but > > > add a note in the commit log that it will be populated in a subsequent > > > patch. > > > > I did, see the last line of the commit description. > > Sorry, I missed that. No problem! > > > > + > > > > static void __do_kernel_fault(unsigned long addr, unsigned int esr, > > > > struct pt_regs *regs) > > > > { > > > > @@ -641,10 +647,40 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) > > > > return 0; > > > > } > > > > > > > > +static void do_tag_recovery(unsigned long addr, unsigned int esr, > > > > + struct pt_regs *regs) > > > > +{ > > > > + static bool reported = false; > > > > + > > > > + if (!READ_ONCE(reported)) { > > > > + report_tag_fault(addr, esr, regs); > > > > + WRITE_ONCE(reported, true); > > > > + } > > > > > > I don't mind the READ_ONCE/WRITE_ONCE here but not sure what they help > > > with. > > > > The fault can happen on multiple cores at the same time, right? In > > that case without READ/WRITE_ONCE() we'll have a data-race here. > > READ/WRITE_ONCE won't magically solve such races. If two CPUs enter > simultaneously in do_tag_recovery(), they'd both read 'reported' as > false and both print the fault info. They won't solve the race condition, but they will solve the data race. I guess here we don't really care about the race condition, as printing a tag fault twice is OK. But having a data race here will lead to KCSAN reports, although won't probably break anything in practice. > If you really care about this race, you need to atomically both read and > update the variable with an xchg() or cmpxchg().