Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp699047ybi; Fri, 21 Jun 2019 06:44:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqywwqspQGKDzgYS/7sDj9GyyyqXhLQN//dyLFk0I/42a/4+HUUptmdYDO5zrhBUOacbDAmm X-Received: by 2002:a63:8f09:: with SMTP id n9mr18316740pgd.249.1561124652819; Fri, 21 Jun 2019 06:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561124652; cv=none; d=google.com; s=arc-20160816; b=Lx1cx2Ia93aR6GoV1RssgqLE6nUHFfZ7M/qAv5plM2LKmXeoVAjGv5YD+HM4JHpGvP Nj8jVAX8ltcYjOn+EFU/8exdmTkPxfwFKM5Lqx7K0ea3AQpXekByi6UUP5bJPHOsEjmV bn3a+mY4CC4l9M/qd/X9Q19CmQudbck38cX20dF7Ey/KbRgJoz0dsK/gtuZHxR6QCjYi BHdkR8ZBAYH7MHzRGOnkPqfJagqgaYE0cZjfffj+dQE7flqD5cmYi3keHp1RdnYtniDc y+NlPAjf58EyPWZllSYwMxeiN1I8P3emjSGS0rbsmne0yZUM3UnxYD6vJQtib39qrCNS trzA== 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:message-id:subject:cc :to:from:date:dkim-signature; bh=NeTgOyo8F0xUENdGPwWSQ5vb2NYfC5iBbqQypdc1EKU=; b=BdLClgSoPDTezi0VLnTqZsNPX/yMVv2mStIDnqSBV8lx/DxI89gI8SSQ1f9HDyzq80 kvaWzsZn2z9Kef1I8YjserGvYYOfMnRMerpmy54MvKyHgkGJVY5meeFNnehi1UeyY8u2 mxPEsTxD6oOEZ+6EdoQ49ZrDjmxPYgcakOfdpOZDL/l4/NiEJ5AVHR8/vJ7WixSc7dj1 MF5Nx4d177xoCR2/CsUFvBm3AQ2HO2oyIyJZaLurCIcjQzTLUWon+LAPFlOiGLjJ4GMc h9qD/jobZCNfOYNQuNHFwMA6auwmGZNMADALK3oR9Dy8GAmSa3T0JNi18+qWYS0TU8zb kaWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fZcpYdKL; 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 a17si2734843pfk.246.2019.06.21.06.43.57; Fri, 21 Jun 2019 06:44:12 -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=fZcpYdKL; 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 S1726209AbfFUNnh (ORCPT + 99 others); Fri, 21 Jun 2019 09:43:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:49562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbfFUNng (ORCPT ); Fri, 21 Jun 2019 09:43:36 -0400 Received: from localhost (unknown [69.71.4.100]) (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 31387206B7; Fri, 21 Jun 2019 13:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561124615; bh=j7CrSlfQAmRQGesg3mqy/vLQAoSNzS1OohkNwYrKLXM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fZcpYdKLbdodX/fGQwJ3O5sT84JfuexstDzFvbQ1a9rlx6xwFxEA7EACKzuwY+iu8 NUjmeZgGcTiSn3xNRjqMNiXG/jbF96btkM5PTzeUKhXS+H/veJaA47U6ETYYTus0mA sdnKlp14BpLpis+dOlOnATjrl4PpN9Et6X1S8MeU= Date: Fri, 21 Jun 2019 08:43:32 -0500 From: Bjorn Helgaas To: John Garry Cc: xuwei5@huawei.com, linuxarm@huawei.com, arm@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, joe@perches.com Subject: Re: [PATCH 1/5] lib: logic_pio: Fix RCU usage Message-ID: <20190621134332.GC82584@google.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> <1561026716-140537-2-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1561026716-140537-2-git-send-email-john.garry@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 20, 2019 at 06:31:52PM +0800, John Garry wrote: > The traversing of io_range_list with list_for_each_entry_rcu() > is not properly protected by rcu_read_lock(), so add it. > > In addition, the list traversing used in logic_pio_register_range() > does not need to use the rcu variant. Not being an RCU expert myself, a few words here about why one path needs protection but the other doesn't would be helpful. This basically restates what the patch *does*, which is obvious from the diff, but not *why*. > Fixes: 031e3601869c ("lib: Add generic PIO mapping method") > Signed-off-by: John Garry > --- > lib/logic_pio.c | 49 +++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 35 insertions(+), 14 deletions(-) > > diff --git a/lib/logic_pio.c b/lib/logic_pio.c > index feea48fd1a0d..761296376fbc 100644 > --- a/lib/logic_pio.c > +++ b/lib/logic_pio.c > @@ -46,7 +46,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) > end = new_range->hw_start + new_range->size; > > mutex_lock(&io_range_mutex); > - list_for_each_entry_rcu(range, &io_range_list, list) { > + list_for_each_entry(range, &io_range_list, list) { > if (range->fwnode == new_range->fwnode) { > /* range already there */ > goto end_register; > @@ -108,26 +108,38 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) > */ > struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode) > { > - struct logic_pio_hwaddr *range; > + struct logic_pio_hwaddr *range, *found_range = NULL; > > + rcu_read_lock(); > list_for_each_entry_rcu(range, &io_range_list, list) { > - if (range->fwnode == fwnode) > - return range; > + if (range->fwnode == fwnode) { > + found_range = range; > + break; > + } > } > - return NULL; > + rcu_read_unlock(); > + > + return found_range; > } > > /* Return a registered range given an input PIO token */ > static struct logic_pio_hwaddr *find_io_range(unsigned long pio) > { > - struct logic_pio_hwaddr *range; > + struct logic_pio_hwaddr *range, *found_range = NULL; > > + rcu_read_lock(); > list_for_each_entry_rcu(range, &io_range_list, list) { > - if (in_range(pio, range->io_start, range->size)) > - return range; > + if (in_range(pio, range->io_start, range->size)) { > + found_range = range; > + break; > + } > } > - pr_err("PIO entry token %lx invalid\n", pio); > - return NULL; > + rcu_read_unlock(); > + > + if (!found_range) > + pr_err("PIO entry token 0x%lx invalid\n", pio); > + > + return found_range; > } > > /** > @@ -180,14 +192,23 @@ unsigned long logic_pio_trans_cpuaddr(resource_size_t addr) > { > struct logic_pio_hwaddr *range; > > + rcu_read_lock(); > list_for_each_entry_rcu(range, &io_range_list, list) { > if (range->flags != LOGIC_PIO_CPU_MMIO) > continue; > - if (in_range(addr, range->hw_start, range->size)) > - return addr - range->hw_start + range->io_start; > + if (in_range(addr, range->hw_start, range->size)) { > + unsigned long cpuaddr; > + > + cpuaddr = addr - range->hw_start + range->io_start; > + > + rcu_read_unlock(); > + return cpuaddr; > + } > } > - pr_err("addr %llx not registered in io_range_list\n", > - (unsigned long long) addr); > + rcu_read_unlock(); > + > + pr_err("addr %pa not registered in io_range_list\n", &addr); > + > return ~0UL; > } > > -- > 2.17.1 >