Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3484671imj; Mon, 11 Feb 2019 22:41:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IZcF//IKru+zdJZq0RSgoiwM50KP89dOjbPjpPYAcKkXPmH316X5nCK9akrLaj/JsN8gXsD X-Received: by 2002:a17:902:2a0a:: with SMTP id i10mr2378083plb.323.1549953673020; Mon, 11 Feb 2019 22:41:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549953673; cv=none; d=google.com; s=arc-20160816; b=yjnz9TsN+DqzFkql2+sgrDLs1TzaPMexyNnz4XAUv3Kv9pNQyYqu6q/VuwTaki4bDs spjUz/PtSX2A8RyJVERracFHYWAM9B+ZTwFvkrDAqu0vVGgHWeM1dMrjnZxC8KjMTl3l Epo4KcPzocN/Wrfl8YZQL6UD6UsYYJCrZNOo5qCvQsly4+I4BmlFONquILJg58YWFCE9 nHFSL4isY8jc4HEWiNILllU1YYLS8sxuUtp2kva2usNPggYrZ9wS5OiaTzi90VRQlCY7 kafwSFJ46bI0OYCBmn8OMw7+qZiF8rRU19Mw4OWuUB/oUIK99up6wA+JRItJvsXFfu0f xeQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=WH5kq+PAShKAq/Y0ruxegZEEOCx7byyFK0fK50EoAVI=; b=LGiIzqIuFd/j0qhch1J90lPX4J9KfKA779UY/hEJO90U70J67JSfU/PZzUAN5RI45r g6OAr3IIe6nloCHse9fVu4k/CVE/fv1wNuZXi6BCSNsW9uG0JJqzHEBIWZaWUjLh4bCR JWbkGB20AhsruZYziSfk/V0QkHbKuo153iz2IGW8cBZy5QE6vPBuaf8q7s3onaM6xp7X ohUaJvlcGM/fYpzNlr0BFyGUZZefZW5L4HxqZAogsFf3lgvA5N5ypOI87vPSJ948EonD LwvTDwPpa6siWAPOXWcI9O+u2S+P/0MRBpjscsji/Y3zI4bF3DnA7LS4ucCfwrxq8H+f eTwg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si11983969plo.406.2019.02.11.22.40.56; Mon, 11 Feb 2019 22:41:13 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbfBLGkw (ORCPT + 99 others); Tue, 12 Feb 2019 01:40:52 -0500 Received: from mga11.intel.com ([192.55.52.93]:54549 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725930AbfBLGkw (ORCPT ); Tue, 12 Feb 2019 01:40:52 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2019 22:40:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,361,1544515200"; d="scan'208";a="142668988" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.151]) by fmsmga002.fm.intel.com with ESMTP; 11 Feb 2019 22:40:49 -0800 From: "Huang\, Ying" To: Daniel Jordan Cc: Andrew Morton , , , Hugh Dickins , "Paul E . McKenney" , Minchan Kim , Johannes Weiner , Tim Chen , Mel Gorman , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Michal Hocko , Andrea Arcangeli , David Rientjes , Rik van Riel , Jan Kara , Dave Jiang , "Andrea Parri" Subject: Re: [PATCH -mm -V7] mm, swap: fix race between swapoff and some swap operations References: <20190211083846.18888-1-ying.huang@intel.com> <20190211190646.j6pdxqirc56inbbe@ca-dmjordan1.us.oracle.com> Date: Tue, 12 Feb 2019 14:40:48 +0800 In-Reply-To: <20190211190646.j6pdxqirc56inbbe@ca-dmjordan1.us.oracle.com> (Daniel Jordan's message of "Mon, 11 Feb 2019 14:06:46 -0500") Message-ID: <87a7j1ldan.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Daniel Jordan writes: > On Mon, Feb 11, 2019 at 04:38:46PM +0800, Huang, Ying wrote: >> +struct swap_info_struct *get_swap_device(swp_entry_t entry) >> +{ >> + struct swap_info_struct *si; >> + unsigned long type, offset; >> + >> + if (!entry.val) >> + goto out; > >> + type = swp_type(entry); >> + si = swap_type_to_swap_info(type); > > These lines can be collapsed into swp_swap_info if you want. Yes. I can use that function to reduce another line from the patch. Thanks! Will do that. >> + if (!si) >> + goto bad_nofile; >> + >> + preempt_disable(); >> + if (!(si->flags & SWP_VALID)) >> + goto unlock_out; > > After Hugh alluded to barriers, it seems the read of SWP_VALID could be > reordered with the write in preempt_disable at runtime. Without smp_mb() > between the two, couldn't this happen, however unlikely a race it is? > > CPU0 CPU1 > > __swap_duplicate() > get_swap_device() > // sees SWP_VALID set > swapoff > p->flags &= ~SWP_VALID; > spin_unlock(&p->lock); // pair w/ smp_mb > ... > stop_machine(...) > p->swap_map = NULL; > preempt_disable() > read NULL p->swap_map Andrea has helped to explain this. Best Regards, Huang, Ying