Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2070294pxa; Sun, 16 Aug 2020 22:48:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+p6egLrtUfz2uHXI2gubMZRFnxGUy+wZZMF/H6J7w5iX8gP8jMgLTobiJeQhusl0go8ar X-Received: by 2002:a17:907:42a0:: with SMTP id ny24mr13723557ejb.328.1597643332167; Sun, 16 Aug 2020 22:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597643332; cv=none; d=google.com; s=arc-20160816; b=cJ9Xlu9nC84vsJwilIgXhG6Sly4eGsB/z5yUaYY2r0EP0SGNyjtQoflnF05f7KjIe6 xilVhTSI7PG1kTFYYi1FlWgab8IrCYkW9fD7KLvODpJcUBz2P8J1yCyjRnuSM4F4MdqL IgsoErnWNglBsgQR7hMvYgZpaIsMC91TiyRxCyDzugSSQqz8bfUYtCEyBMk6iS18IPKU QPm0OOFIL3ZWOhCn64ZMq3pawxhKoPF6EpjjpMG0qAUTuGsX2bSmlZ2JGpSegZuuD2TI /i3jAnJQM34gUj5WUNFwtScys6SYmkIgGLaIhm4Hkm+B8HryXdSLkFvOkIOu2DxWBVz0 0BiQ== 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; bh=fOtYAde77Ate6H9m2xw3coLsg66ROx40UMeI9cajClU=; b=o+jF8/XoT2F98G6cb8dFmC+itWgwDGyDlWfmvPuvSUPAueEeSAnzm9xPPMS+CnGbSf Dq2SbcUNdIccyJIOnGASGCXkCdu9V/QZ0KgafLBqGwpMyWdujl65XUYpZut45eUI9DyA 6do0JrHN57kuB/KKFra70maUcVD3W+axGbFA/LJWA/8u3EMucsyqi6bXUUuqY08jnRzl yGQq5uxte6/M5JH9kbSoOnBO6idfZAXVHj56PiMU8gQqxLRabgvZdepxuRwi6yDtqpJ2 ofmdRQ3MtEp3rxWYDJpt974ShmMPlGruFQg+VPgyNV+9DL3DLDxdpvoUm37DBHd721vz nBTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k10si5023639ejr.684.2020.08.16.22.48.29; Sun, 16 Aug 2020 22:48:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbgHQFpm (ORCPT + 99 others); Mon, 17 Aug 2020 01:45:42 -0400 Received: from verein.lst.de ([213.95.11.211]:55031 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgHQFpm (ORCPT ); Mon, 17 Aug 2020 01:45:42 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 69E1767357; Mon, 17 Aug 2020 07:45:38 +0200 (CEST) Date: Mon, 17 Aug 2020 07:45:38 +0200 From: Christoph Hellwig To: Cong Wang Cc: Coly Li , linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Linux Kernel Network Developers , stable , LKML , Chaitanya Kulkarni , Christoph Hellwig , Hannes Reinecke , Jan Kara , Jens Axboe , Mikhail Skorzhinskii , Philipp Reisner , Sagi Grimberg , Vlastimil Babka Subject: Re: [PATCH v5 1/3] net: introduce helper sendpage_ok() in include/linux/net.h Message-ID: <20200817054538.GA11705@lst.de> References: <20200816071518.6964-1-colyli@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 16, 2020 at 10:55:09AM -0700, Cong Wang wrote: > On Sun, Aug 16, 2020 at 1:36 AM Coly Li wrote: > > > > The original problem was from nvme-over-tcp code, who mistakenly uses > > kernel_sendpage() to send pages allocated by __get_free_pages() without > > __GFP_COMP flag. Such pages don't have refcount (page_count is 0) on > > tail pages, sending them by kernel_sendpage() may trigger a kernel panic > > from a corrupted kernel heap, because these pages are incorrectly freed > > in network stack as page_count 0 pages. > > > > This patch introduces a helper sendpage_ok(), it returns true if the > > checking page, > > - is not slab page: PageSlab(page) is false. > > - has page refcount: page_count(page) is not zero > > > > All drivers who want to send page to remote end by kernel_sendpage() > > may use this helper to check whether the page is OK. If the helper does > > not return true, the driver should try other non sendpage method (e.g. > > sock_no_sendpage()) to handle the page. > > Can we leave this helper to mm subsystem? > > I know it is for sendpage, but its implementation is all about some > mm details and its two callers do not belong to net subsystem either. > > Think this in another way: who would fix it if it is buggy? I bet mm people > should. ;) No. This is all about a really unusual imitation in sendpage, which is pretty much unexpected. In fact the best thing would be to make sock_sendpage do the right thing and call sock_no_sendpage based on this condition, so that driver writers don't have to worry at all.