From patchwork Tue Jul 31 04:48:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jane Chu X-Patchwork-Id: 10549861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6DC896FA for ; Tue, 31 Jul 2018 04:48:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17892A097 for ; Tue, 31 Jul 2018 04:48:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5A092A0BB; Tue, 31 Jul 2018 04:48:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74C4E2A0B3 for ; Tue, 31 Jul 2018 04:48:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F54C6B0003; Tue, 31 Jul 2018 00:48:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5A5366B0005; Tue, 31 Jul 2018 00:48:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4469F6B0007; Tue, 31 Jul 2018 00:48:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ua0-f199.google.com (mail-ua0-f199.google.com [209.85.217.199]) by kanga.kvack.org (Postfix) with ESMTP id 0E3326B0003 for ; Tue, 31 Jul 2018 00:48:46 -0400 (EDT) Received: by mail-ua0-f199.google.com with SMTP id l22-v6so4767344uak.2 for ; Mon, 30 Jul 2018 21:48:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=ecWrOfJUuTTg06v8CRGavcrhDo1TfCR+siQgb9sg6n8=; b=sfCQuMcXFaKaMFtrOP0xyeDa3aOFsrKy71FiPT2byUBfZ5+I/DMPxCamXOv7nVHQUN TXhAPS1xcp9Zeapugye02XsipBGYrTJbFNw6FQ5MqIlaAFnbNrFyciub4FmCffWa5XYQ x+96PTZas4T0Niibhd8qG1583vA5OjKkLpMQPYF6ekwIehuwUMbcpyFRLo24CddvhDgs LWSKoZbyT5NeanryxIaGv+/32mQveeiHv8rV4C4O3lFkS4iEuw3QL91ZM3lxSLNowm83 ft78O9Ugm2VQcsTWpVlx68AowtEEeF7b5szZEo/c3pcEQaeqgvAQOGj1JyrYQiz8eMj2 MkYA== X-Gm-Message-State: AOUpUlHT69GOc6eIiPxpxUwjb5M4uNv3h4fcwP+zmDnQsvMWyOcbTQOK eOZAp3ZM2rAP2d3KHMGLbyrRp/qGs5EK/VYPse7A+TZ2EpwTPn0bqPkNSWF0uGMDJ5xXvbIohNR FT4Rb8P6aiG3GinUu5Bf4YmHOcyztl9WSWTmSbZGRmOQItVs2gdUGJVc5qV1XpN/iNg== X-Received: by 2002:ab0:16dc:: with SMTP id g28-v6mr14029812uaf.7.1533012525707; Mon, 30 Jul 2018 21:48:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcTuVlj1we3ph88b7zbe2aYSRBiDG8DFGSTpHVIMK6uU8aLNVNZclsYar+vuoldn+/G9bYG X-Received: by 2002:ab0:16dc:: with SMTP id g28-v6mr14029787uaf.7.1533012525017; Mon, 30 Jul 2018 21:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533012524; cv=none; d=google.com; s=arc-20160816; b=tmsV8+je3AU1Sp5QDdNZ5GxwqpMp6CyL8dteR6p+8A79x0CZHAfGrPqSWh0jFyOuTw 89+ty6cMQfqeyZHY5d9i1LLZpkwQiSLjQSMUOwNyRCOlb58BeEHPsCsrrd0nog6bUysE zAYxRMV8L+Jc7k15bNNEkrG/muUJB5zQL873DvqyV+oqk/Fa0Dw52FUCDb7G+di3bALC cmQujWe22Zc7DMWKH9uH5+FyHNJspqoqyEawGOUkblMAtrysD2oIpasSGW+7HTpLMX0P t2sasZbHRo5TGxnKsSFyVArg3CfHznPDJXFa/+ABMyz07eSwUH7z1mP7xit0cQmH9aAz yEGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=ecWrOfJUuTTg06v8CRGavcrhDo1TfCR+siQgb9sg6n8=; b=g6tyyWDtgmas5g1+xFoLP8rVZjLoxJAA4NPu5mxaEKjdYQgyrPsGvvZCnTFPPMe2u4 pgKBl4BVdsYjcXTFmick0Zo/SGfoHR0bQ4r2vK5UB3cs2OzYeByfoxhOcUYmfK0QJTlW hgJVJ2zSGxFFDnZRj1+Fbm0ZUL6ligDwh6AUPE3OScxm+wErALe9XuDbZHNeZBBMWB44 Z6K193H7oWhVPoBia7lWtOQger0W+TDE+hdqEpFDl8j/xSHorJpMdDffsheEivOd1yh3 /cJGsrMJnmUXfYhNlUX3/jHzoal/rSDG/ZnjS1+WVCdUk1bmZQmQPK4U7hGQYHYor+9f nbYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ugtLY+8P; spf=pass (google.com: domain of jane.chu@oracle.com designates 141.146.126.79 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2130.oracle.com (aserp2130.oracle.com. [141.146.126.79]) by mx.google.com with ESMTPS id d76-v6si5296856vkd.211.2018.07.30.21.48.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jul 2018 21:48:44 -0700 (PDT) Received-SPF: pass (google.com: domain of jane.chu@oracle.com designates 141.146.126.79 as permitted sender) client-ip=141.146.126.79; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ugtLY+8P; spf=pass (google.com: domain of jane.chu@oracle.com designates 141.146.126.79 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6V4jJp0041994; Tue, 31 Jul 2018 04:48:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=ecWrOfJUuTTg06v8CRGavcrhDo1TfCR+siQgb9sg6n8=; b=ugtLY+8POU47/ZNizjWbIXQ7JBGAd0+H6U8tlUQUgANOHmiEQcYyUvfMCrPDjqY4cAYx NATixJ+edOUqQfcIGwTSHHAnLETlzYpWGDUYefmpDvA3MrYld+qbzmzCRz78EOyLYsA2 NRrV0lyQd6pbL4vOQQyq1xflIo3OjqHjuj70ZE2BDhqj8fNx5UMJANedWxbeWn04XSei 7H47Cf7QLzcy/ZEo6f6yQfnJ+M2qBrMkk89Osm6K3XUmYxCYJ68v5OcIwL33EHNk5vny v/A6eggxpLmDT1gK1HZmIjOM4X0WfClz7sm+hr7nhKeQsoyGyY9Df5V0wGr+rVRirl+M 5A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2kge0cyady-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jul 2018 04:48:41 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6V4mcpw013969 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jul 2018 04:48:40 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6V4mZ9P015349; Tue, 31 Jul 2018 04:48:35 GMT Received: from brm-x4600-03.us.oracle.com (/10.80.150.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 30 Jul 2018 21:48:35 -0700 From: Jane Chu To: akpm@linux-foundation.org Cc: dan.j.williams@intel.com, mhocko@suse.com, jack@suse.cz, jglisse@redhat.com, mike.kravetz@oracle.com, dave@stgolabs.net, linux-mm@kvack.org, linux-nvdimm@lists.01.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, jane.chu@oracle.com Subject: [PATCH v2] ipc/shm.c add ->pagesize function to shm_vm_ops Date: Mon, 30 Jul 2018 22:48:31 -0600 Message-Id: <20180731044831.26036-1-jane.chu@oracle.com> X-Mailer: git-send-email 2.15.GIT MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8970 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807310051 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: X-Virus-Scanned: ClamAV using ClamSMTP 05ea88608d4e13 ("mm, hugetlbfs: introduce ->pagesize() to vm_operations_struct") adds a new ->pagesize() function to hugetlb_vm_ops, intended to cover all hugetlbfs backed files. With System V shared memory model, if "huge page" is specified, the "shared memory" is backed by hugetlbfs files, but the mappings initiated via shmget/shmat have their original vm_ops overwritten with shm_vm_ops, so we need to add a ->pagesize function to shm_vm_ops. Otherwise, vma_kernel_pagesize() returns PAGE_SIZE given a hugetlbfs backed vma, result in below BUG: fs/hugetlbfs/inode.c 443 if (unlikely(page_mapped(page))) { 444 BUG_ON(truncate_op); [ 242.268342] hugetlbfs: oracle (4592): Using mlock ulimits for SHM_HUGETLB is deprecated [ 282.653208] ------------[ cut here ]------------ [ 282.708447] kernel BUG at fs/hugetlbfs/inode.c:444! [ 282.818957] Modules linked in: nfsv3 rpcsec_gss_krb5 nfsv4 ... [ 284.025873] CPU: 35 PID: 5583 Comm: oracle_5583_sbt Not tainted 4.14.35-1829.el7uek.x86_64 #2 [ 284.246609] task: ffff9bf0507aaf80 task.stack: ffffa9e625628000 [ 284.317455] RIP: 0010:remove_inode_hugepages+0x3db/0x3e2 .... [ 285.292389] Call Trace: [ 285.321630] hugetlbfs_evict_inode+0x1e/0x3e [ 285.372707] evict+0xdb/0x1af [ 285.408185] iput+0x1a2/0x1f7 [ 285.443661] dentry_unlink_inode+0xc6/0xf0 [ 285.492661] __dentry_kill+0xd8/0x18d [ 285.536459] dput+0x1b5/0x1ed [ 285.571939] __fput+0x18b/0x216 [ 285.609495] ____fput+0xe/0x10 [ 285.646030] task_work_run+0x90/0xa7 [ 285.688788] exit_to_usermode_loop+0xdd/0x116 [ 285.740905] do_syscall_64+0x187/0x1ae [ 285.785740] entry_SYSCALL_64_after_hwframe+0x150/0x0 Link: http://lkml.kernel.org/r/20180727211727.5020-1-jane.chu@oracle.com Fixes: 05ea88608d4e13 ("mm, hugetlbfs: introduce ->pagesize() to vm_operations_struct") Signed-off-by: Jane Chu Suggested-by: Mike Kravetz Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Acked-by: Davidlohr Bueso Cc: Dan Williams Cc: Michal Hocko Cc: Jan Kara Cc: Jérôme Glisse Cc: Davidlohr Bueso Cc: Manfred Spraul Cc: Signed-off-by: Andrew Morton --- --- ipc/shm.c | 12 ++++++++++++ mm/hugetlb.c | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/ipc/shm.c b/ipc/shm.c index 051a3e1fb8df..fefa00d310fb 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -427,6 +427,17 @@ static int shm_split(struct vm_area_struct *vma, unsigned long addr) return 0; } +static unsigned long shm_pagesize(struct vm_area_struct *vma) +{ + struct file *file = vma->vm_file; + struct shm_file_data *sfd = shm_file_data(file); + + if (sfd->vm_ops->pagesize) + return sfd->vm_ops->pagesize(vma); + + return PAGE_SIZE; +} + #ifdef CONFIG_NUMA static int shm_set_policy(struct vm_area_struct *vma, struct mempolicy *new) { @@ -554,6 +565,7 @@ static const struct vm_operations_struct shm_vm_ops = { .close = shm_close, /* callback for when the vm-area is released */ .fault = shm_fault, .split = shm_split, + .pagesize = shm_pagesize, #if defined(CONFIG_NUMA) .set_policy = shm_set_policy, .get_policy = shm_get_policy, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 039ddbc574e9..3103099f64fd 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3167,6 +3167,13 @@ static vm_fault_t hugetlb_vm_op_fault(struct vm_fault *vmf) return 0; } +/* + * When a new function is introduced to vm_operations_struct and added + * to hugetlb_vm_ops, please consider adding the function to shm_vm_ops. + * This is because under System V memory model, mappings created via + * shmget/shmat with "huge page" specified are backed by hugetlbfs files, + * their original vm_ops are overwritten with shm_vm_ops. + */ const struct vm_operations_struct hugetlb_vm_ops = { .fault = hugetlb_vm_op_fault, .open = hugetlb_vm_op_open,