Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp851133ybh; Wed, 11 Mar 2020 12:06:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtSpITbEdLLG4xnV40vBOa/pWKAi+9n/yC5Uvuc3612VmzEhHcxCjCMeR5ur6gvtTjEX29B X-Received: by 2002:aca:4cc9:: with SMTP id z192mr123268oia.134.1583953587030; Wed, 11 Mar 2020 12:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583953587; cv=none; d=google.com; s=arc-20160816; b=pfhNaIWYmuFw7BH1zP63cNKEd+Qpu2zcbgAWx+8PZLMCh/SxBtlvH78afKZ6FPps7a LvURJsV2+aVY6OX5fP1gYD7Lxn+A7eoWZ3fHQnLoWkQ2197F5vtTe4A4aTlwce+dPxiZ LDdL4GN+TULFp5MLILl6QwrEFcfTbxWHpMoL+ftbK+5TSfXsjCnRIzkVYALi9s/P4g4P RBQW3gg9E2vLbwv1hTcjuIRX9G1+dA7Q4Dd3xVcFXdw5rTuVxL/yMquL/8L6EPeIb1yf KIhUOmT57djBOI1dRZ0EVt2cZcp3o4p2F3fiHqg/4oqgd4FfHkJ+w8JbBz08RufIoPg8 I0eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=oUSZ7sM7FB4d6YGH5oZd4dEG1XcXLEOYhyzWilDIceE=; b=cAZ+gUQnFqmRIIfoCkr8pqkMzn/OmHg9p0behz4Nd28WqSvhY3tQSOzsDY+E3/2krr 6tw2cmNr59HkBRRVH/ycFXxVmx2d+j+4A3frpxV1ZAwPO0SKMjql7Oo9YQTmvR68f9B2 qkCi2Wa6PhirRVQh7Uu8tTTbSvfTiNPodp/v5LSEbMQLC8K+rhZ68kRhu8KhrqBitsir BA/bp47TrjzSTqfXQcLtQe3hBIt9SzO+ZmTdWG0ZtPeSbAg9nWmJOv+hxKs/MNJD9zHt hU2/ypTk4D94R+sNjF21ffDFNXmV0ro/h0ybjNWqZX3vZPfWTfnDmyPIKBNXSbJOfjmM u/4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kVLQ46+B; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si1530259otk.238.2020.03.11.12.06.01; Wed, 11 Mar 2020 12:06:27 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=kVLQ46+B; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730915AbgCKTEt (ORCPT + 99 others); Wed, 11 Mar 2020 15:04:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:50038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730805AbgCKTEt (ORCPT ); Wed, 11 Mar 2020 15:04:49 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F3E320739; Wed, 11 Mar 2020 19:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583953489; bh=0qTjkhntA0kD+y2Mff5lp9EgvstRLbEV9hT9cLx7ZlU=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=kVLQ46+B5v0R2xYEYXra/c3sQ+JFadjhoeB42QEdYhnrkkvIBKLSe+m7ufdEbCaoQ GrJOAPyy9tQibmQq/r3qsl41PA5NU/oQjG+vKjmS1gIB4GUpdMAS3J0SmheyteOd93 fU9R60xvTdI8GoANhUkySlg8tU2vE/XqOxLa7eG8= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 046F03522D70; Wed, 11 Mar 2020 12:04:48 -0700 (PDT) Date: Wed, 11 Mar 2020 12:04:47 -0700 From: "Paul E. McKenney" To: Borislav Petkov Cc: Qian Cai , tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, elver@google.com, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next] x86/mm/pat: mark an intentional data race Message-ID: <20200311190447.GA3199@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <1581343816-6490-1-git-send-email-cai@lca.pw> <20200311161756.GE3470@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200311161756.GE3470@zn.tnic> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 11, 2020 at 05:17:56PM +0100, Borislav Petkov wrote: > + Paul. > > On Mon, Feb 10, 2020 at 09:10:16AM -0500, Qian Cai wrote: > > cpa_4k_install could be accessed concurrently as noticed by KCSAN, > > > > read to 0xffffffffaa59a000 of 8 bytes by interrupt on cpu 7: > > cpa_inc_4k_install arch/x86/mm/pat/set_memory.c:131 [inline] > > __change_page_attr+0x10cf/0x1840 arch/x86/mm/pat/set_memory.c:1514 > > __change_page_attr_set_clr+0xce/0x490 arch/x86/mm/pat/set_memory.c:1636 > > __set_pages_np+0xc4/0xf0 arch/x86/mm/pat/set_memory.c:2148 > > __kernel_map_pages+0xb0/0xc8 arch/x86/mm/pat/set_memory.c:2178 > > kernel_map_pages include/linux/mm.h:2719 [inline] > > > > write to 0xffffffffaa59a000 of 8 bytes by task 1 on cpu 6: > > cpa_inc_4k_install arch/x86/mm/pat/set_memory.c:131 [inline] > > __change_page_attr+0x10ea/0x1840 arch/x86/mm/pat/set_memory.c:1514 > > __change_page_attr_set_clr+0xce/0x490 arch/x86/mm/pat/set_memory.c:1636 > > __set_pages_p+0xc4/0xf0 arch/x86/mm/pat/set_memory.c:2129 > > __kernel_map_pages+0x2e/0xc8 arch/x86/mm/pat/set_memory.c:2176 > > kernel_map_pages include/linux/mm.h:2719 [inline] > > > > Both accesses are due to the same "cpa_4k_install++" in > > cpa_inc_4k_install. A data race here could be potentially undesirable: > > depending on compiler optimizations or how x86 executes a non-LOCK'd > > increment, it may lose increments, corrupt the counter, etc. Since this > > counter only seems to be used for printing some stats, this data race > > itself is unlikely to cause harm to the system though. Thus, mark this > > intentional data race using the data_race() marco. > > > > Suggested-by: Macro Elver > > Signed-off-by: Qian Cai > > --- > > arch/x86/mm/pat/set_memory.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c > > index c4aedd00c1ba..ea0b6df950ee 100644 > > --- a/arch/x86/mm/pat/set_memory.c > > +++ b/arch/x86/mm/pat/set_memory.c > > @@ -128,7 +128,7 @@ static inline void cpa_inc_2m_checked(void) > > > > static inline void cpa_inc_4k_install(void) > > { > > - cpa_4k_install++; > > + data_race(cpa_4k_install++); > > } > > > > static inline void cpa_inc_lp_sameprot(int level) > > -- > > Acked-by: Borislav Petkov Applied, thank you both! Thanx, Paul