From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 5BC96302149 for ; Wed, 8 Apr 2026 15:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775663162; cv=none; b=PfYlqLU/gng/TotOF888SCSunjjPIKyr+lYbaBg7gsgyka/EIF4aHR3UtCyJkyr370VttcZuSjqSmmAOU9jxhRiy38rTaOuWG795aiYfOQimqFicpJNNhNsoZJ6G1H5MxUWLuD8JIp+1mjiVLlMZ2t9Nk01Z1PTfCUpBQy3TCrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775663162; c=relaxed/simple; bh=EpoYwT9XpYkFKIDpBSoSGRLXTFOwYlbmoSFKhbs5VHM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g6VKGNnEuqVHl3TU8orlnbBVmnHJAS1oQ+sP75KUnSTmLMiXQhbHsaMOyA8DKit2Z8ExknU9HCGDEY/v+fay2JA+m24ncRFNk05Wi5lNRejR4uzSK6gd8ta1toxtyGRfU44ykSiYcyQe0/OJlqmzjJmn9mJcjHqPhRmqQE2FYI0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Zu7SlHoM; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Zu7SlHoM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775663160; 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=ABVcnSBYw67/dNbfG+cq2X/5dXQSJpLjV8UMfC8U4II=; b=Zu7SlHoMpxRHks9m+4YbjMaCIVNXoRd+htwEq0Dt/8w6HrlT3gkoRGil1Ar+nsyJCZ6pCE AOM/550GG6v+vFjm6361mCsA0Nx7AVOAJKXh3rqGVGm+BqtOj2/R3lKPotPXkNeyWbkIyz twcfprS5uokAFR+0hlUdoNXFcykF/fM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-QrTHQVknNKmkhMeU6X5Y2w-1; Wed, 08 Apr 2026 11:45:58 -0400 X-MC-Unique: QrTHQVknNKmkhMeU6X5Y2w-1 X-Mimecast-MFC-AGG-ID: QrTHQVknNKmkhMeU6X5Y2w_1775663156 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 133171956052; Wed, 8 Apr 2026 15:45:56 +0000 (UTC) Received: from localhost (unknown [10.72.112.14]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2C55419560A6; Wed, 8 Apr 2026 15:45:53 +0000 (UTC) Date: Wed, 8 Apr 2026 23:45:49 +0800 From: Baoquan He To: Chris Li Cc: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org, baohua@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] mm/swap: use swap_ops to register swap device's methods Message-ID: References: <20260328075812.11060-1-21cnbao@gmail.com> <20260328075812.11060-3-21cnbao@gmail.com> 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-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 04/08/26 at 02:26am, Chris Li wrote: > On Tue, Apr 7, 2026 at 11:11 PM Baoquan He wrote: > > > > On 03/30/26 at 08:30pm, Chris Li wrote: > > ...... > > > > @@ -608,6 +593,39 @@ static void swap_read_folio_bdev_async(struct folio *folio, > > > > submit_bio(bio); > > > > } > > > > > > > > +static const struct swap_ops bdev_fs_swap_ops = { > > > > + .read_folio = swap_read_folio_fs, > > > > + .write_folio = swap_writepage_fs, > > > > +}; > > > > + > > > > +static const struct swap_ops bdev_sync_swap_ops = { > > > > + .read_folio = swap_read_folio_bdev_sync, > > > > + .write_folio = swap_writepage_bdev_sync, > > > > +}; > > > > + > > > > +static const struct swap_ops bdev_async_swap_ops = { > > > > + .read_folio = swap_read_folio_bdev_async, > > > > + .write_folio = swap_writepage_bdev_async, > > > > +}; > > > > + > > > > +void setup_swap_ops(struct swap_info_struct *sis) > > > > > > setup_swap_ops()` needs to return an indication of an error. > > > The error is that sis->ops is NULL or op->read_folio == NULL or > > > op->write_folio == NULL. > > > If there is an error, we should fail the swapon. > > > > Thanks for your comments. > > > > In the current patches, there's no chance any of these happens: > > sis->ops is NULL or > > op->read_folio == NULL or > > op->write_folio == NULL > > I am aware of that. Adding the check in setup_swap_ops() responds to > the WARN_ONCE check on op->write_folio() feedback. > In fact, we should never have a case where op->read_folio or > op->write_folio is NULL. However, I can see that other future swap ops > can be NULL. e.g. Notify swap entry free. It is hard to enforce that > some fields can be NULL and others can't. So having code safeguard it > is fine. > > > Because it's a if-else logic in setup_swap_ops(), adding an error > > checking looks a little weird. I think it's worth adding the error > > checking in setup_swap_ops() later when we have new swap_ops added > > and there's potential any of above three cases could happen. > > Adding the check in setup_swap_ops() is to remove the useless warning > check on the caller side of op->read_folio(). If you think the check > is not needed setup_swap_ops(), then it is not needed in > op->read_folio() either. > The WARN_ONCE() then kernel panic on reading op->read_folio does not > make sense. The check was added due to one of the feedback that what > if this call back is NULL. > > I prefer to keep the `setup_swap_ops()` function responsible for the > NULL check, due to the discussion history surrounding it. > I'm also fine with adding the NULL check later. However, the NULL > check needs to be consistent across the patch series. The other NULL > check inside WARN_ONCE before the caller site op->read_folio() and > op->write_folio() needs to be removed. > > Does that make sense? Both is fine to me. I will change to do the checking in setup_swap_ops(). By the way, I tend to rename setup_swap_ops() as init_swap_ops(), is it OK to you? Thanks Baoquan