Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3034598imj; Mon, 11 Feb 2019 12:40:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IZUKRYVziMj+KGyZDrq+iAlj84nQTHDyEtjBuMKRVUuhiw185EPUY7LDUFl1fGbDB+ECj+H X-Received: by 2002:a65:6116:: with SMTP id z22mr74925pgu.265.1549917625697; Mon, 11 Feb 2019 12:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549917625; cv=none; d=google.com; s=arc-20160816; b=k7hQ6RkrSigoa8ywWk9u78jeSRw3+M4q+Z/fWenxJu0jMmrW4l0PnevlneeQE3oInu iV3JdNP51tu5G2nU3N7fNLmE4RBDkLLuGd7WwGvtyVn5HpFWp9Fg6MwG6nUxjbtxS0Q/ 3LIPezivLVf2ZsQfCYtBC6D2C8sHBId5j2l5B34E8A28bK0cBoitNs7/uS8JB+SPK+xN W490Xkg+T8Ntn4Fhlj68hSeIZgY6WxzhM10+l5BJ95YveJPySd5fdHDy39uLjzohUv7r RW35r+OV63sNKBhYXAT9W97Mx1tiTyf2OHDoRPuJ/wPka/kLrWhg/Cpmb80zQDz22NAy GmbQ== 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=1byxMH4cS5DA8jf3Vc8nsnHQYzCL4Eu4MKOQbBwKaQA=; b=cOay3DpcdQlatRri8d10Phuj5kvdk3noBgIyyijbC39fgu5MURVR6TsujsfgN+VLVT ghcs5YATDOpyyBXFxkccdL6DAyPvl1NY9/XnCr1FGdM2CEJ6U+xBYygcvbqIJRaCrG4Q Q44YIh35OjRLXWef4vn5l3sCa2y7B5JZuQj94538xi2uov8XA48I4RqZFIA03Ap9H5lr vXm/BxSHj9+BnmtNh4MbelS7NvJO9migOn0zMnf+zIJtEiux9DVJi6S8fYXp+RdFQ0ih pVH+t88ve6+EhnCEy1kY7t0wBmcsikHB1nOgaKTfHEjEWgLrctBkY8IqslsboAoARwe1 TZuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=OH6iGjT0; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j21si11058771pll.150.2019.02.11.12.40.09; Mon, 11 Feb 2019 12:40:25 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=OH6iGjT0; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387540AbfBKTHt (ORCPT + 99 others); Mon, 11 Feb 2019 14:07:49 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:38318 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732057AbfBKTHs (ORCPT ); Mon, 11 Feb 2019 14:07:48 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1BJ4E2e093492; Mon, 11 Feb 2019 19:06:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=1byxMH4cS5DA8jf3Vc8nsnHQYzCL4Eu4MKOQbBwKaQA=; b=OH6iGjT02b6/sqHMTKcJDBzQT4lRUfMvpdAE4yTmcBYmg6JDX6kzAyCh6yi/bhMvTvz+ EZkNZW5nHkfFFrK0i9jWl06MAr/dTk8xbndOKqJBxETuBv2piWoc8SAwh+K8su1I3JfG h1KvmwVgAQMwEHdI1mwehooCsqH8CPZfbx7Y1O87wJpV42KSbutbbc8E1kp27qoRSiwu N5o6Pf0cxHeEzr5YQT3DCA67eG99QUBlFNYaKKI3kvTEmHdUJn5XLnLWSzpwQdPFRcR9 Zh2IziawY916WZ5eebEABc+7Gt4lhELKgmZDTUl0mUlVdWUIviQKAObD8LIYGVC9lNKs Dw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2qhredqpq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Feb 2019 19:06:29 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1BJ6SeF031440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Feb 2019 19:06:28 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1BJ6QlV020484; Mon, 11 Feb 2019 19:06:26 GMT Received: from ca-dmjordan1.us.oracle.com (/10.211.9.48) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 11 Feb 2019 11:06:26 -0800 Date: Mon, 11 Feb 2019 14:06:46 -0500 From: Daniel Jordan To: "Huang, Ying" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, 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 , Daniel Jordan , Andrea Parri Subject: Re: [PATCH -mm -V7] mm, swap: fix race between swapoff and some swap operations Message-ID: <20190211190646.j6pdxqirc56inbbe@ca-dmjordan1.us.oracle.com> References: <20190211083846.18888-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190211083846.18888-1-ying.huang@intel.com> User-Agent: NeoMutt/20180323-268-5a959c X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9164 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=764 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902110139 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > + 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