Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp275369imm; Tue, 14 Aug 2018 19:03:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxjzzRmdFP54+NjdfaopcsdoPIMQcSoCTPUjQbZkCB01zjiRYkzNL2H5O3YFPxju2Jp6zci X-Received: by 2002:a62:198e:: with SMTP id 136-v6mr4613864pfz.103.1534298627118; Tue, 14 Aug 2018 19:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534298627; cv=none; d=google.com; s=arc-20160816; b=j0rTm9E172kUJ9o+/KDkm1VmYdsk2FqwbxN7AMbVGhc03tRrYQ0DMYE7uEsyEIcrvU T5h9N0jsy/KrbNr4ecGiFp3o1dM0gGSSqvUJyuTyaYmahNE3Xgmbn/hPHUcx3yJzxl25 aTgOvmK68hNRD/310Bevl3peIgtST4q/b7VEclV8zPIjhxPFc9ucG6H2ssl0ZWw4Sps5 WxHk6uYcA2aFlMGjakGZDtYhJa+pBv3npkGFp8S77LFXVG/t5oBoRpG4DxfAVmdSYZEL ipbOxkifb1Zhkq13GZOl3vtTWJJ7ZkE1aD+5lUAe9FUZ0xQra+3l1luw0W8PGrWDRfF2 Sy+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=sKaQtJTUbTeuqNo3gJGa8vD/yzdxMxxE+e4NR/krCDg=; b=UTTrWcORERMAsxHPCcwbCZqEakVgv18eZplY3MmXPLk5UrCtbARqT4rK6O+OnyclJq qQi3yF6phJ+IrBnb/xnTv8MBD4qqZhv+J07WEG9sEVbyCVvNJYuwEEQsqDGFw3suY6P1 ts+O95XQPjDy+TRNTvtf4tf6dpBeTIUIfusTq5WqUGyv7Cmhe+iHk/h0rZPbpv0u5pv/ /+7BwBay0uvlaWMkd4o1x0Yb3zQu1XIRQuN1qvH/kAnUAbLH98l1WWr1umutzIY2IveI L1jImBOGaxY3CVyguX3DDvkWRWTaVutiIY3nW2gtVOzBMrpS/a2VTzAPbtd/6Jj0l0nw fMrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=e3gVpugS; 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 y8-v6si25125607pfk.75.2018.08.14.19.03.30; Tue, 14 Aug 2018 19:03:47 -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=@linux-foundation.org header.s=google header.b=e3gVpugS; 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 S1726300AbeHOEwh (ORCPT + 99 others); Wed, 15 Aug 2018 00:52:37 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:50815 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbeHOEwh (ORCPT ); Wed, 15 Aug 2018 00:52:37 -0400 Received: by mail-it0-f66.google.com with SMTP id j81-v6so108036ite.0 for ; Tue, 14 Aug 2018 19:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sKaQtJTUbTeuqNo3gJGa8vD/yzdxMxxE+e4NR/krCDg=; b=e3gVpugSZ1ofuhrjv913M/L63n2xDFKKevV3MdKOdTjKvJrRo8hj2diGMAzplgTsOc 9rTUQzcsw7VrLrIa8MmiaWKE/rL3YuRnXGbtmUvUpTo0wUGycoj8V0h4qGDYpP3meFio LQslornutYH0FPtaeRB3F6AgHIlDgJvnTFLiA= 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=sKaQtJTUbTeuqNo3gJGa8vD/yzdxMxxE+e4NR/krCDg=; b=JDdu5K9cTt5MzclCnQDbDX3gxSqQuRcv8Uy9cEy+vFJVjdd0EGPpSXArupnQQ1dvKK jwK2XOHh+yOvCZPzpwkD28W+zzSxkOXKMcbVnuAOzGBlB0AuuCBRYQPzeakIfSKJVJCE JLlPk3TmwtnG0ILvBUAXg16/lWKumL9j0Y6BgXFh6+2tjafDMt4PvaMqLVZHT4mp+hRB YO9BvqjaHW9dddYA8fczWMZ6gQYz0ZpTg5bsn0xqBudQ/uosJXQP68csgStnZQTtDpX9 diYjoJEiT28EzwhDfZbS7G8APYOqeTZYDGfmGXnQmGXOcECRwiN9NPFTASA2K486G6Hh 9XUw== X-Gm-Message-State: AOUpUlFCpDLmzdwAuRqVG95lXNghwAbAxcQ3kiSqAIzeSbegc1B1wEU/ f+KSAYcHbdGIZBCmXL3MMtwIk9LXuU3U8Nkp0P8= X-Received: by 2002:a02:1bdc:: with SMTP id 89-v6mr20838972jas.72.1534298558096; Tue, 14 Aug 2018 19:02:38 -0700 (PDT) MIME-Version: 1.0 References: <20180814221735.62804-1-wnukowski@google.com> <20180814225716.GA3224@localhost.localdomain> In-Reply-To: From: Linus Torvalds Date: Tue, 14 Aug 2018 19:02:27 -0700 Message-ID: Subject: Re: [PATCH] Bugfix for handling of shadow doorbell buffer. To: wnukowski@google.com Cc: keith.busch@linux.intel.com, Jens Axboe , Sagi Grimberg , Linux Kernel Mailing List , linux-nvme , Keith Busch , yigitfiliz@google.com, Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 14, 2018 at 6:35 PM Michal Wnukowski wrote: > > I got confused after comaring disassembly of this code with and > without volatile keyword. Thanks for the correction. Note that _usually_, the "volatile" has absolutely no impact. When there is one read in the source code, it's almost always one access in the generated code too. That's particularly true if the read like this access do dbbuf_ei: if (!nvme_dbbuf_need_event(*dbbuf_ei, value, old_value)) is only used as an argument to a real function call. But if that function is an inline function (which it is), and the argument ends up getting used multiple times (which in this case it is not), then it is possible in theory that gcc ends up saying "instead of reading the value once, and keep it in a register, I'll just read it again for the second time". That happens rarely, but it _can_ happen without the volatile (or the READ_ONCE()). The advantage of READ_ONCE() over using "volatile" in a data structure tends to be that you explicitly mark the memory accesses that you care about. That's nice documentation for whoever reads the code (and it's not unheard of that the _same_ data structure is sometimes volatile, and sometimes not - for example, the data structure might be protected by a lock - not volatile - but people might use an optimistic lockless access to the value too - when it ends up being volatile. So then it's really good to explicitly use READ_ONCE() for the volatile cases where you show that you know that you're now doing something special that really depends on memory ordering or other magic "access exactly once" behavior. > > I'm assuming that's the actual controller hardware, but it needs a > > comment about *that* access being ordered too, because if it isn't, > > then ordering this side is pointless. > > The other side in this case is not actual controller hardware, but > virtual one (the regular hardware should rely on normal MMIO > doorbells). Ok, Maybe worth adding a one-line note about the ordering guarantees by the virtual controller accesses. Linus