From: "Jan Beulich" Subject: [PATCH] amd iommu: improve parse_event_log_entry() Date: Wed, 23 May 2012 08:02:11 +0100 Message-ID: <4FBCA79302000078000855AF@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part735D8D63.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Wei Wang List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part735D8D63.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - message table should be static (no need to set it up each time the function gets executed) - don't bail on out-of-range event code values - use message table also to print the kind of otherwise unhandled event codes Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -568,14 +568,18 @@ static void parse_event_log_entry(struct u32 code; u64 *addr; int count =3D 0; - char * event_str[] =3D {"ILLEGAL_DEV_TABLE_ENTRY", - "IO_PAGE_FAULT", - "DEV_TABLE_HW_ERROR", - "PAGE_TABLE_HW_ERROR", - "ILLEGAL_COMMAND_ERROR", - "COMMAND_HW_ERROR", - "IOTLB_INV_TIMEOUT", - "INVALID_DEV_REQUEST"}; + static const char *const event_str[] =3D { +#define EVENT_STR(name) [IOMMU_EVENT_##name - 1] =3D #name + EVENT_STR(ILLEGAL_DEV_TABLE_ENTRY), + EVENT_STR(IO_PAGE_FAULT), + EVENT_STR(DEV_TABLE_HW_ERROR), + EVENT_STR(PAGE_TABLE_HW_ERROR), + EVENT_STR(ILLEGAL_COMMAND_ERROR), + EVENT_STR(COMMAND_HW_ERROR), + EVENT_STR(IOTLB_INV_TIMEOUT), + EVENT_STR(INVALID_DEV_REQUEST) +#undef EVENT_STR + }; =20 code =3D get_field_from_reg_u32(entry[1], IOMMU_EVENT_CODE_MASK, IOMMU_EVENT_CODE_SHIFT); @@ -599,13 +603,6 @@ static void parse_event_log_entry(struct IOMMU_EVENT_CODE_SHIFT); } =20 - if ( (code > IOMMU_EVENT_INVALID_DEV_REQUEST) || - (code < IOMMU_EVENT_ILLEGAL_DEV_TABLE_ENTRY) ) - { - AMD_IOMMU_DEBUG("Invalid event log entry!\n"); - return; - } - if ( code =3D=3D IOMMU_EVENT_IO_PAGE_FAULT ) { device_id =3D iommu_get_devid_from_event(entry[0]); @@ -633,8 +630,10 @@ static void parse_event_log_entry(struct } else { - AMD_IOMMU_DEBUG("event 0x%08x 0x%08x 0x%08x 0x%08x\n", entry[0], - entry[1], entry[2], entry[3]); + AMD_IOMMU_DEBUG("%s %08x %08x %08x %08x\n", + code <=3D ARRAY_SIZE(event_str) ? event_str[code = - 1] + : "event", + entry[0], entry[1], entry[2], entry[3]); } =20 memset(entry, 0, IOMMU_EVENT_LOG_ENTRY_SIZE); --=__Part735D8D63.1__= Content-Type: text/plain; name="amd-iommu-event-log-strings.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="amd-iommu-event-log-strings.patch" amd iommu: improve parse_event_log_entry()=0A=0A- message table should be = static (no need to set it up each time the=0A function gets executed)=0A- = don't bail on out-of-range event code values=0A- use message table also to = print the kind of otherwise unhandled=0A event codes=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- a/xen/drivers/passthrough/amd/iomm= u_init.c=0A+++ b/xen/drivers/passthrough/amd/iommu_init.c=0A@@ -568,14 = +568,18 @@ static void parse_event_log_entry(struct=0A u32 code;=0A = u64 *addr;=0A int count =3D 0;=0A- char * event_str[] =3D = {"ILLEGAL_DEV_TABLE_ENTRY",=0A- "IO_PAGE_FAULT",= =0A- "DEV_TABLE_HW_ERROR",=0A- = "PAGE_TABLE_HW_ERROR",=0A- "ILLEGAL_COMMAND_= ERROR",=0A- "COMMAND_HW_ERROR",=0A- = "IOTLB_INV_TIMEOUT",=0A- "INVALID_DEV_R= EQUEST"};=0A+ static const char *const event_str[] =3D {=0A+#define = EVENT_STR(name) [IOMMU_EVENT_##name - 1] =3D #name=0A+ EVENT_STR(ILL= EGAL_DEV_TABLE_ENTRY),=0A+ EVENT_STR(IO_PAGE_FAULT),=0A+ = EVENT_STR(DEV_TABLE_HW_ERROR),=0A+ EVENT_STR(PAGE_TABLE_HW_ERROR),= =0A+ EVENT_STR(ILLEGAL_COMMAND_ERROR),=0A+ EVENT_STR(COMMAND_= HW_ERROR),=0A+ EVENT_STR(IOTLB_INV_TIMEOUT),=0A+ EVENT_STR(IN= VALID_DEV_REQUEST)=0A+#undef EVENT_STR=0A+ };=0A =0A code =3D = get_field_from_reg_u32(entry[1], IOMMU_EVENT_CODE_MASK,=0A = IOMMU_EVENT_CODE_SHIFT);=0A@@ -599,13 +603,6 = @@ static void parse_event_log_entry(struct=0A = IOMMU_EVENT_CODE_SHIFT);=0A }=0A =0A- if ( (code > = IOMMU_EVENT_INVALID_DEV_REQUEST) ||=0A- (code < IOMMU_EVENT_ILLEGAL_= DEV_TABLE_ENTRY) )=0A- {=0A- AMD_IOMMU_DEBUG("Invalid event log = entry!\n");=0A- return;=0A- }=0A-=0A if ( code =3D=3D = IOMMU_EVENT_IO_PAGE_FAULT )=0A {=0A device_id =3D iommu_get_dev= id_from_event(entry[0]);=0A@@ -633,8 +630,10 @@ static void parse_event_log= _entry(struct=0A }=0A else=0A {=0A- AMD_IOMMU_DEBUG("eve= nt 0x%08x 0x%08x 0x%08x 0x%08x\n", entry[0],=0A- = entry[1], entry[2], entry[3]);=0A+ AMD_IOMMU_DEBUG("%s %08x %08x = %08x %08x\n",=0A+ code <=3D ARRAY_SIZE(event_str) ? = event_str[code - 1]=0A+ = : "event",=0A+ entry[0], entry[1], entry[2], = entry[3]);=0A }=0A =0A memset(entry, 0, IOMMU_EVENT_LOG_ENTRY_SIZE)= ;=0A --=__Part735D8D63.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part735D8D63.1__=--