From patchwork Fri Apr 22 01:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12822655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A69BAC433F5 for ; Fri, 22 Apr 2022 01:58:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D85136B0072; Thu, 21 Apr 2022 21:58:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D32D16B0073; Thu, 21 Apr 2022 21:58:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD34C6B0074; Thu, 21 Apr 2022 21:58:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id AADCB6B0072 for ; Thu, 21 Apr 2022 21:58:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 741AC120353 for ; Fri, 22 Apr 2022 01:58:44 +0000 (UTC) X-FDA: 79382856168.21.A9C8C86 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 0410340017 for ; Fri, 22 Apr 2022 01:58:41 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id y129so4921238qkb.2 for ; Thu, 21 Apr 2022 18:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uLSUoJVHY9YahU9ZfsHKs+fyZqAXDk9bw1q64p7TeGw=; b=SDDQDb+KtvzNlx1BiMLG+U3FNgd0ZIbI/xsjbp7+9yewARhdm04dup8G+/5HX//eVy F2Z2xyLQvxf1fyXUT1W3quthdRjk3qgCLxDUwABX661x7XiB4somepwjjULpOlxtC72t FGShHCCXiI2JXXLVF8sYaNSZJFvIk3YpS4BbdYHsZ50CUvObGdd2bnGkgmbjfI+U2W3W x9v7PA2byW9YpJhJKJt0ugCEbILsbD8dPu81W1jy//mzEbgopMP1kk+bhMtx8nlklWFG OICnj8fQaW1lK5ejKQH9WlNaTCBA/5yQ6iewZ6TxRiFlp13hCfK1Cdh9y0PjINGBiCVj tsaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uLSUoJVHY9YahU9ZfsHKs+fyZqAXDk9bw1q64p7TeGw=; b=rE6z/WIr6rroZ1v8739S5ksUT6tGVuTYgFB1n6K8UJ5Q1olS0n8ZwDbG7GWZs9AIHq HaznI/xJahavzODR4MTa5kTKs0/n5WRAD3Qfl0ISFK21zMDR8/0Z5EjXnpiNSW/8ztJQ wtCXJB+1UYeuFuIfrFKNDruATKOu/T/DIiIkwPS0V2dv2wvn3YNMPWb9A9x+1M9WKj8D m+8qaAn29x0Wo36UMCOgoNMKa/qOwKDxpbePgU3kK10mcLpxQUxrZQyutawOubNAhVKQ gdt5ufzzsWy0zb3BmPWq7bnU92CTn3reatvmh6z93RDDgqpNqBtwcPb3P3OM3qdWszVB jXVg== X-Gm-Message-State: AOAM532+oUpt2461y3VCT75KrbA0jCCBGHPrzXRgWlL6lThMsoHIylAZ XA8ycdu0Gt+Q4jCy9FFKJI8= X-Google-Smtp-Source: ABdhPJwbb+hX1GyuoG6RhLXFmap/nHREn/i7hG1lL8BKFt76KqbGGPIv5RjssMe27P0pNe+Iy6R3JA== X-Received: by 2002:a05:620a:2416:b0:69f:534:4a37 with SMTP id d22-20020a05620a241600b0069f05344a37mr1348217qkn.527.1650592723047; Thu, 21 Apr 2022 18:58:43 -0700 (PDT) Received: from localhost ([2601:c4:c432:668:da50:5094:8aba:8f5e]) by smtp.gmail.com with ESMTPSA id t10-20020a05620a034a00b0069c06c95bf7sm322910qkm.14.2022.04.21.18.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 18:58:42 -0700 (PDT) From: Yury Norov To: Andrew Morton , Minchan Kim , John Hubbard , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yury Norov Subject: [PATCH v2] mm/gup: fix comments to pin_user_pages_*() Date: Thu, 21 Apr 2022 18:58:39 -0700 Message-Id: <20220422015839.1274328-1-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SDDQDb+K; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.222.179 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0410340017 X-Stat-Signature: 41ewnn1cjrjgws7o4gkbehj31qwh5n8y X-HE-Tag: 1650592721-82899 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: pin_user_pages API forces FOLL_PIN in gup_flags, which means that the API requires struct page **pages to be provided (not NULL). However, the comment to pin_user_pages() clearly allows for passing in a NULL @pages argument. Remove the incorrect comments, and add WARN_ON_ONCE(!pages) calls to enforce the API. It has been independently spotted by Minchan Kim and confirmed with John Hubbard: https://lore.kernel.org/all/YgWA0ghrrzHONehH@google.com/ CC: Minchan Kim CC: John Hubbard Signed-off-by: Yury Norov (NVIDIA) Reviewed-by: John Hubbard --- v1: https://lore.kernel.org/linux-mm/92a2715c-3c98-251d-9195-872d1cf01f9d@nvidia.com/#t v2: Remove comment for WARN_ON_ONCE() and reword commit message. mm/gup.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index f598a037eb04..b1e96b6192de 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2871,6 +2871,9 @@ int pin_user_pages_fast(unsigned long start, int nr_pages, if (WARN_ON_ONCE(gup_flags & FOLL_GET)) return -EINVAL; + if (WARN_ON_ONCE(!pages)) + return -EINVAL; + gup_flags |= FOLL_PIN; return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages); } @@ -2893,6 +2896,9 @@ int pin_user_pages_fast_only(unsigned long start, int nr_pages, */ if (WARN_ON_ONCE(gup_flags & FOLL_GET)) return 0; + + if (WARN_ON_ONCE(!pages)) + return 0; /* * FOLL_FAST_ONLY is required in order to match the API description of * this routine: no fall back to regular ("slow") GUP. @@ -2920,8 +2926,7 @@ EXPORT_SYMBOL_GPL(pin_user_pages_fast_only); * @nr_pages: number of pages from start to pin * @gup_flags: flags modifying lookup behaviour * @pages: array that receives pointers to the pages pinned. - * Should be at least nr_pages long. Or NULL, if caller - * only intends to ensure the pages are faulted in. + * Should be at least nr_pages long. * @vmas: array of pointers to vmas corresponding to each page. * Or NULL if the caller does not require them. * @locked: pointer to lock flag indicating whether lock is held and @@ -2944,6 +2949,9 @@ long pin_user_pages_remote(struct mm_struct *mm, if (WARN_ON_ONCE(gup_flags & FOLL_GET)) return -EINVAL; + if (WARN_ON_ONCE(!pages)) + return -EINVAL; + gup_flags |= FOLL_PIN; return __get_user_pages_remote(mm, start, nr_pages, gup_flags, pages, vmas, locked); @@ -2957,8 +2965,7 @@ EXPORT_SYMBOL(pin_user_pages_remote); * @nr_pages: number of pages from start to pin * @gup_flags: flags modifying lookup behaviour * @pages: array that receives pointers to the pages pinned. - * Should be at least nr_pages long. Or NULL, if caller - * only intends to ensure the pages are faulted in. + * Should be at least nr_pages long. * @vmas: array of pointers to vmas corresponding to each page. * Or NULL if the caller does not require them. * @@ -2976,6 +2983,9 @@ long pin_user_pages(unsigned long start, unsigned long nr_pages, if (WARN_ON_ONCE(gup_flags & FOLL_GET)) return -EINVAL; + if (WARN_ON_ONCE(!pages)) + return -EINVAL; + gup_flags |= FOLL_PIN; return __gup_longterm_locked(current->mm, start, nr_pages, pages, vmas, gup_flags); @@ -2994,6 +3004,9 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, if (WARN_ON_ONCE(gup_flags & FOLL_GET)) return -EINVAL; + if (WARN_ON_ONCE(!pages)) + return -EINVAL; + gup_flags |= FOLL_PIN; return get_user_pages_unlocked(start, nr_pages, pages, gup_flags); }