From patchwork Wed Jun 8 12:20:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ankitprasad.r.sharma@intel.com X-Patchwork-Id: 9164515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 23375604DB for ; Wed, 8 Jun 2016 12:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13BC12723E for ; Wed, 8 Jun 2016 12:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 089652823D; Wed, 8 Jun 2016 12:47:36 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06BB22723E for ; Wed, 8 Jun 2016 12:47:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 180D46E9E6; Wed, 8 Jun 2016 12:47:33 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 03DDE6E9E2 for ; Wed, 8 Jun 2016 12:47:16 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 08 Jun 2016 05:47:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,439,1459839600"; d="scan'208";a="997763801" Received: from ankitprasad-desktop.iind.intel.com ([10.223.82.74]) by fmsmga002.fm.intel.com with ESMTP; 08 Jun 2016 05:47:15 -0700 From: ankitprasad.r.sharma@intel.com To: intel-gfx@lists.freedesktop.org Date: Wed, 8 Jun 2016 17:50:40 +0530 Message-Id: <1465388441-23085-11-git-send-email-ankitprasad.r.sharma@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465388441-23085-1-git-send-email-ankitprasad.r.sharma@intel.com> References: <1465388441-23085-1-git-send-email-ankitprasad.r.sharma@intel.com> Cc: akash.goel@intel.com, Ankitprasad Sharma Subject: [Intel-gfx] [PATCH 10/11] drm/i915: Disable use of stolen area by User when Intel RST is present X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ankitprasad Sharma The BIOS RapidStartTechnology may corrupt the stolen memory across S3 suspend due to unalarmed hibernation, in which case we will not be able to preserve the User data stored in the stolen region. Hence this patch tries to identify presence of the RST device on the ACPI bus, and disables use of stolen memory (for persistent data) if found. v2: Updated comment, updated/corrected new functions private to driver (Chris/Tvrtko) v3: Disabling stolen by default, wait till required acpi changes to detect device presence are pulled in (Ankit) v4: Enabled stolen by default as required acpi changes are merged (Ankit) v5: renamed variable, is IS_ENABLED() in place of #ifdef, use char* instead of structures (Lukas) Signed-off-by: Ankitprasad Sharma Cc: Lukas Wunner Reviewed-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem.c | 8 ++++++++ drivers/gpu/drm/i915/i915_gem_stolen.c | 12 ++++++++++++ drivers/gpu/drm/i915/intel_acpi.c | 7 +++++++ 4 files changed, 38 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 81e0551..5ac1996 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1340,6 +1340,16 @@ struct i915_gem_mm { */ bool busy; + /** + * Stolen will be lost upon hibernate (as the memory is unpowered). + * Across resume, we expect stolen to be intact - however, it may + * also be utililised by third parties (e.g. Intel RapidStart + * Technology) and if so we have to assume that any data stored in + * stolen across resume is lost and we set this flag to indicate that + * the stolen memory is volatile. + */ + bool volatile_stolen; + /* the indicator for dispatch video commands on two BSD rings */ unsigned int bsd_ring_dispatch_index; @@ -3704,6 +3714,7 @@ static inline int intel_opregion_get_panel_type(struct drm_i915_private *dev) #endif /* intel_acpi.c */ +bool intel_detect_acpi_rst(void); #ifdef CONFIG_ACPI extern void intel_register_dsm_handler(void); extern void intel_unregister_dsm_handler(void); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index b5a2604..3b66b68 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -391,8 +391,16 @@ static struct drm_i915_gem_object * i915_gem_alloc_object_stolen(struct drm_device *dev, size_t size) { struct drm_i915_gem_object *obj; + struct drm_i915_private *dev_priv = dev->dev_private; int ret; + if (dev_priv->mm.volatile_stolen) { + /* Stolen may be overwritten by external parties + * so unsuitable for persistent user data. + */ + return ERR_PTR(-ENODEV); + } + mutex_lock(&dev->struct_mutex); obj = i915_gem_object_create_stolen(dev, size); if (IS_ERR(obj)) diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c index 2518ebb..0e6203c 100644 --- a/drivers/gpu/drm/i915/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c @@ -492,6 +492,18 @@ int i915_gem_init_stolen(struct drm_device *dev) */ drm_mm_init(&dev_priv->mm.stolen, 0, ggtt->stolen_usable_size); + /* If the stolen region can be modified behind our backs upon suspend, + * then we cannot use it to store nonvolatile contents (i.e user data) + * as it will be corrupted upon resume. + */ + dev_priv->mm.volatile_stolen = false; + if (IS_ENABLED(CONFIG_SUSPEND)) { + /* BIOSes using RapidStart Technology have been reported + * to overwrite stolen across S3, not just S4. + */ + dev_priv->mm.volatile_stolen = intel_detect_acpi_rst(); + } + return 0; } diff --git a/drivers/gpu/drm/i915/intel_acpi.c b/drivers/gpu/drm/i915/intel_acpi.c index eb638a1..60ccb39 100644 --- a/drivers/gpu/drm/i915/intel_acpi.c +++ b/drivers/gpu/drm/i915/intel_acpi.c @@ -23,6 +23,8 @@ static const u8 intel_dsm_guid[] = { 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c }; +static const char *irst_id = "INT3392"; + static char *intel_dsm_port_name(u8 id) { switch (id) { @@ -162,3 +164,8 @@ void intel_register_dsm_handler(void) void intel_unregister_dsm_handler(void) { } + +bool intel_detect_acpi_rst(void) +{ + return acpi_dev_found(irst_id); +}