From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E61A3B95E0 for ; Thu, 23 Apr 2026 02:37:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776911864; cv=none; b=mvluDIVEyugyMWYvgethYnOhVP+zs571yzQS7jM8SfaI2LRyDUwRGg/HEUS1822rlWaljsk8EZ1XT+P8qY/SDWUeHpDHWsjKAxTlA26RqDNhJpCnb/G1pSSkp2a47Vr+dPd1kcVpRT+sR27IZVEaz2jlHcHc6Du8YWBZAodREzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776911864; c=relaxed/simple; bh=s47MhLIeNOAkU7irD2eeJW8TFHU249Ia0v7fSqy3wwI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W9qF+fiv+PeGrntXiZWexBLwfWqErfP1FpoJCLrfSyMWrm2o+wDeBRwWLg8/9NTzcmioaFgfGx6r0X85IBCUP0m325oyrGzlgxvxlDkc671B8mCqTN2SF4T37ENUlf6NAbzquAkkA9A9VF/43kh4477eWH40H0RFuQge9QYHMDs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gxpqvqGO; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gxpqvqGO" Date: Thu, 23 Apr 2026 10:37:28 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776911859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tmDiF8YpdHuzHjKufxDweaNIBD9kEOy5KYDQCBH6Ybs=; b=gxpqvqGObABR3XmALkCVtRl60wpafyapcdgXLHER2+3286Xx8nYEp1Wk+JCN57xjytirSM QQIoOX3NkhT9Evh5vmtNQuEHQR0nJ4eBq6Q/OJnI89OkRGh94rB+izVxggdc3X/BDfGDsc Jf2brEyoTbedxo1F2P6ZJoVanRRGX00= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Baoquan He To: Chris Li , akpm@linux-foundation.org Cc: linux-mm@kvack.org, usama.arif@linux.dev, baohua@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/3] mm/swap: use swap_ops to register swap device's methods Message-ID: References: <20260417033951.1111038-1-baoquan.he@linux.dev> <20260417033951.1111038-3-baoquan.he@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT On 04/22/26 at 05:33pm, Chris Li wrote: > On Tue, Apr 21, 2026 at 6:48 PM Baoquan He wrote: > > > > On 04/17/26 at 07:30pm, Chris Li wrote: > > > On Thu, Apr 16, 2026 at 8:40 PM Baoquan He wrote: > > ...snip... > > > > +int init_swap_ops(struct swap_info_struct *sis) > > > > +{ > > > > + /* > > > > + * ->flags can be updated non-atomically, but that will > > > > + * never affect SWP_FS_OPS, so the data_race is safe. > > > > + */ > > > > + if (data_race(sis->flags & SWP_FS_OPS)) > > > > + sis->ops = &bdev_fs_swap_ops; > > > > + /* > > > > + * ->flags can be updated non-atomically, but that will > > > > + * never affect SWP_SYNCHRONOUS_IO, so the data_race is safe. > > > > + */ > > > > + else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO)) > > > > + sis->ops = &bdev_sync_swap_ops; > > > > + else > > > > + sis->ops = &bdev_async_swap_ops; > > > > + > > > > + if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) > > > > + return -1; > > > Nitpick: > > > > > > For int type error return, you should use -EINVAL or some thing with > > > error code. If you don't care about error code, change the return type > > > to bool instead. > > > > Thanks for careful reviewing, returning -EINVAL looks better, I will > > change like that and repost. > > You don't have to repost it as a new series. You can post one small > incremental update for the -EINVAL change and ask Andrew to fold it > in. > > Hi Andrew, > > I think this swap ops series can be merge to mm-unstable with the > review. Keep in mind that Baoquan might have a very minor follow up > patch relate to -EINAL error code. The incremental update is as below. I have built and test it. diff --git a/mm/swap_io.c b/mm/swap_io.c index 77aa8373c087..e2710d5fb44e 100644 --- a/mm/swap_io.c +++ b/mm/swap_io.c @@ -625,7 +625,7 @@ int init_swap_ops(struct swap_info_struct *sis) sis->ops = &bdev_async_swap_ops; if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) - return -1; + return -EINVAL; return 0; } diff --git a/mm/swapfile.c b/mm/swapfile.c index af81fa212f1e..7644049a0919 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3518,10 +3518,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) goto bad_swap_unlock_inode; } - if (init_swap_ops(si)) { - error = -EINVAL; + if (error = init_swap_ops(si)) goto bad_swap_unlock_inode; - } si->max = maxpages; si->pages = maxpages - 1;