From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C6E61A00BE for ; Wed, 20 Apr 2022 16:47:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B9DF541104; Wed, 20 Apr 2022 16:47:31 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 4E971406A2; Wed, 20 Apr 2022 16:47:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650466048; x=1682002048; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=e/hwOrhdQAF47KB3HxuVoLWJ1Tk2SMivV16jEKmquzM=; b=OV27v8cRK81cmiwps4WQIjcIllc79iqCuhC422UVdsp0EQyHWaaGVZwc 8wzCgmyMyT/HT9LL9qbFivwA+0heGGVha6iD4tKQCrs68F9t8wIpMHCp1 XCizkcV42j+q/vMxYT/PnVKPIoORpv6H7dSCdi+0HIB2rQGJWX1YpkleY j8hvP000BK1AQYWbNdYNpCCnPH1SkgVyM1fCU+gvBF4Ri+RfqV0KO5PFe Ql4knoInbFuNXDRXTR58Q4ftYdH8cUAm5XUY/CmV2z8Tl9wMAyPMHfKsu P67tw1brKca12heKN4QjDCczGTyHa/n640/K3U9vdtbjrc0Rriy49v0px A==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="264213997" X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="264213997" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 07:47:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="702661381" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga001.fm.intel.com with ESMTP; 20 Apr 2022 07:47:27 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 20 Apr 2022 07:47:26 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Wed, 20 Apr 2022 07:47:26 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.169) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Wed, 20 Apr 2022 07:47:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MeIm+6g1BIWl2ovf8V+vY1dEh705wOv9lVnTmuAtfInSHWx+Hu/f1ohdIHj3NianuukK5i1mEFksc85VHBkAsCrgoImuEm/O+BsDGLZc8+wjKQ9d+zMelQzt8OhRjwFZz7RVNDaQkqe4ud4O1feANJiSlJcxGuGGLTOYOYKZkFAAWDwbldpZ7DOS3yb+f11/qY/vii/RMzVCyk4H3fKNOVg143bHU3tPNFjb4bQTXy9Xu/nZjx+ODvlnBMVCkxhBAaxDhjgvM0PjPhBum+0+2rpBo6G8XlIPKjiJ6oSSA06Tn7q9I2/oQor1dDI10V2pwb89dgfi9Vl3/BIsMQw0CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wbvW89Y8CgAXn52ntZKcKRfPlGpThLxG+FiU95FlbdM=; b=nQlsZYn8ko4uE5MYyuY/1kueDYzSAnF+fpk9S4HEn/F31OOeDOmJ4lbXRbDfhmH8fYX+OAF6lxSJE/LvaHW83H1nRLz1VpF6tUjNSuQophto1zpcPaW1R/7KOh7x1yd+3tCbuyCtK6fTZQQYxmFREfTnClZ3S9zfn8O6nnFMI+/1tFJxYKZazGy7uxDMXihUuyMG07kX8O5IZAKpUEoH4IjjPN1lBLCr6AJvt0HW/o6zLHoirRpOzzkNeD9LfhO885Je4ZBY9deEAyDKUAh6QC9QG5dURMxgt1oAJDLRBuHrcU1qQXGP7bwzJi68gSzP8qJJhzJSGoGkLZtPKIoBUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from PH0PR11MB5093.namprd11.prod.outlook.com (2603:10b6:510:3e::23) by SA2PR11MB4795.namprd11.prod.outlook.com (2603:10b6:806:118::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Wed, 20 Apr 2022 14:47:25 +0000 Received: from PH0PR11MB5093.namprd11.prod.outlook.com ([fe80::28af:8ec5:1817:1af1]) by PH0PR11MB5093.namprd11.prod.outlook.com ([fe80::28af:8ec5:1817:1af1%3]) with mapi id 15.20.5164.025; Wed, 20 Apr 2022 14:47:24 +0000 Message-ID: <419bb7fc-cb04-10cf-a40a-5dba39323f9e@intel.com> Date: Wed, 20 Apr 2022 15:47:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.7.0 Subject: Re: [PATCH 2/3] mem: fix ASan shadow for remapped memory segments Content-Language: en-US To: David Marchand , CC: , , , Xueqin Lin , Zhihong Peng References: <20220415173127.3838-1-david.marchand@redhat.com> <20220415173127.3838-3-david.marchand@redhat.com> From: "Burakov, Anatoly" In-Reply-To: <20220415173127.3838-3-david.marchand@redhat.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: DU2P250CA0013.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:231::18) To PH0PR11MB5093.namprd11.prod.outlook.com (2603:10b6:510:3e::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9206b1e6-ad6f-4ec9-dc89-08da22dcaeb8 X-MS-TrafficTypeDiagnostic: SA2PR11MB4795:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EMkkOJy73Kv9sSgKZWrIG5yT239LG1sL9WfN/UA4uAPmheKkIah533g2JJAYRf3gCLcG9myIj1X4ot374RLzsZFqAyLGaw3bLtibm2X2+7UHZQTcbDF4GISnd53Zro+qGZFBL44jjcb3EECRKdKXdPwfMggF/PwcsY4UTO+rrtqi3lt/RGI+f17AhC1MA5/q6AMoWl6YGoyB2q+ymA4JeZYf3t9NXCAW7wpTH0J7jZ46Qic66T5t1Yd0blHz1dMfL7BtVKBLPOFP/vm3BtooKF6ir8UVy+CMdQosn89Itrd258OFInps4TuFlbSPSFeweKO1IL1VDli4B3z/bV+DgC6PIILxDZgEyzXviMKwYREI3+8qj9vVOBZnPzJPia/c1bhnB2TPpL6pQpwjpnftPEmgqI/Jf+as0XKwP4JPX+RLd6wCiGfXf5cv1TnLDLM5m8vNv3yA4R+MkLxFoay9cgD36xHp/VIJl7xRs9zFuzP5458Eyn8AU0fDyEIYFgvG91dUnNol8RcTi3YFks31gkTlCIq+ry2sHOcOQ3JBtLc28O/wW493DVmaq87Fa6I0vmFMKxT9oq6go32EcEvgFTVcqVw8CsTgMA5PItwQ04I8QHoSy2+WnJuiePCqNogwEaxkV4mEh3QavXNkGu6Z4CyOMuljRK3zWsKpquqT95t3yrmrjl4BKYiyNA+PBZe0TaCv/Gega41m+jPxUkmNKE06eBauRdWw+Hm/GDHAj1g= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR11MB5093.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(508600001)(6486002)(31696002)(36756003)(186003)(2906002)(6506007)(26005)(5660300002)(6512007)(83380400001)(86362001)(31686004)(38100700002)(66476007)(66556008)(4326008)(82960400001)(8676002)(107886003)(2616005)(66946007)(8936002)(6666004)(53546011)(54906003)(316002)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SENIRnFXRDZ1ZWlIWWJLVHhDd3prQ1hvWG5sUCtXZkhHY2ZwUUFhVnNkdFlu?= =?utf-8?B?MFpvMDV3Y3luakpXZExqNElqcGZBY2VqRXFkdGV5NHUyZk1mUGp3NFE1d1Nv?= =?utf-8?B?Q05VVTNUajZxQkdNV0RWTllwaUhlQ2JQWkhTbXp5QUxZRmRiUlFBdUxVK3B0?= =?utf-8?B?Y05EL2ZicDFYS0VKVUxDU1NMdXBkWUlvaU5qTERVQ0szeEczN2VjSmtwRVdh?= =?utf-8?B?YkwrckVSTEtKeTQ1U0NLcy9LY2hkSTUzTFpPdmV4Wm9ZUjRjUDh2UXIyalB3?= =?utf-8?B?RFJCMkhSck1MZlZFMS9qZUlGTElOWmFpYndDakxUSmFoUmpnTHM4NUhBMHcy?= =?utf-8?B?OEVQdlZUV09VTUVKMlR4MEJwQXJVazkzYWpzaXF5a29rRmlnaFJQQnRsck44?= =?utf-8?B?bG5y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TWXUycjNVV3J2THdOVHRN?= =?utf-8?B?VDBZUTZZTHVhUzIyNzVjcFlzZHU1Ykl0OWZlZE5CQzVRUFRiWDVyOENYVlh2?= =?utf-8?B?N283azdYMEJsMStTV0J5RlB4Qk9OazhzOWFhS05FNjM5MmtIdWdVTmczZkRT?= =?utf-8?Q?s4Q6oGemtA/iDsmU=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 9206b1e6-ad6f-4ec9-dc89-08da22dcaeb8 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5093.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2022 14:47:24.8346 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LhZNJi1x4n7SzF85PPu0UN3r9NNUIULJRWGm1B9rUo9HFXqZ634K0lH/hOndU8fDbU24Rh49BrWzebPhbStWeGcAl1YxBycMlkNunYRjGgM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB4795 X-OriginatorOrg: intel.com X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On 15-Apr-22 6:31 PM, David Marchand wrote: > When releasing some memory, the allocator can choose to return some > pages to the OS. At the same time, this memory was poisoned in ASAn > shadow. Doing the latter made it impossible to remap this same page > later. > On the other hand, without this poison, the OS would pagefault in any > case for this page. > > Remove the poisoning for unmapped pages. > > Bugzilla ID: 994 > Fixes: 6cc51b1293ce ("mem: instrument allocator for ASan") > Cc: stable@dpdk.org > > Signed-off-by: David Marchand > --- > lib/eal/common/malloc_elem.h | 4 ++++ > lib/eal/common/malloc_heap.c | 12 +++++++++++- > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/lib/eal/common/malloc_elem.h b/lib/eal/common/malloc_elem.h > index 228f178418..b859003722 100644 > --- a/lib/eal/common/malloc_elem.h > +++ b/lib/eal/common/malloc_elem.h > @@ -272,6 +272,10 @@ old_malloc_size(struct malloc_elem *elem) > > #else /* !RTE_MALLOC_ASAN */ > > +static inline void > +asan_set_zone(void *ptr __rte_unused, size_t len __rte_unused, > + uint32_t val __rte_unused) { } > + > static inline void > asan_set_freezone(void *ptr __rte_unused, size_t size __rte_unused) { } > > diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c > index 6c572b6f2c..5913d9f862 100644 > --- a/lib/eal/common/malloc_heap.c > +++ b/lib/eal/common/malloc_heap.c > @@ -860,6 +860,7 @@ malloc_heap_free(struct malloc_elem *elem) > size_t len, aligned_len, page_sz; > struct rte_memseg_list *msl; > unsigned int i, n_segs, before_space, after_space; > + bool unmapped_pages = false; > int ret; > const struct internal_config *internal_conf = > eal_get_internal_configuration(); > @@ -999,6 +1000,13 @@ malloc_heap_free(struct malloc_elem *elem) > > /* don't care if any of this fails */ > malloc_heap_free_pages(aligned_start, aligned_len); > + /* > + * Clear any poisoning in ASan for the associated pages so that > + * next time EAL maps those pages, the allocator can access > + * them. > + */ > + asan_set_zone(aligned_start, aligned_len, 0x00); > + unmapped_pages = true; > > request_sync(); > } else { > @@ -1032,7 +1040,9 @@ malloc_heap_free(struct malloc_elem *elem) > > rte_mcfg_mem_write_unlock(); > free_unlock: > - asan_set_freezone(asan_ptr, asan_data_len); > + /* Poison memory range if belonging to some still mapped pages. */ > + if (!unmapped_pages) > + asan_set_freezone(asan_ptr, asan_data_len); > > rte_spinlock_unlock(&(heap->lock)); > return ret; I suspect the patch should be a little more complicated than that. When we unmap pages, we don't necessarily unmap the entire malloc element, it could be that we have a freed allocation like so: | malloc header | free space | unmapped space | free space | next malloc header | So, i think the freezone should be set from asan_ptr till aligned_start, and then from (aligned_start + aligned_len) till (asan_ptr + asan_data_len). Does that make sense? -- Thanks, Anatoly